Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] End-to-end test service starting point #74

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ build: clean config generate
cd cmd/migrate ; make build
echo "build admin"
cd cmd/admin ; make build
echo "build e2e"
cd cmd/e2e ; make build
echo "build entree"
cd cmd/entree ; make build
echo "build extract"
Expand Down
8 changes: 8 additions & 0 deletions cmd/e2e/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build:
go build -buildvcs=false -o service.exe

run:
go run *.go

clean:
rm -f service.exe
9 changes: 9 additions & 0 deletions cmd/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# get-page

```
python get-page.py "URL" page_name
```

will pull down the plain text of a page, and wrap it in an HTML body. It will save the page into the `static` folder, adding a `.html` to the end.

This is to create pages for testing the search engine; only pull CC0/public domain text.
21 changes: 21 additions & 0 deletions cmd/e2e/get-page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import bs4
import click
import requests

@click.command()
@click.argument('url')
@click.argument('page_name')
def main(url, page_name):
r = requests.get(url)
url_contents = r.text
soup = bs4.BeautifulSoup(url_contents, features="lxml")
contents = soup.getText()
with open(f"static/{page_name}.html", 'w') as fp:
fp.write("<html>\n")
fp.write(f"<head><title>{page_name}</title></head>\n")
fp.write("<body>\n")
fp.write(contents.strip())
fp.write("\n</body></html>\n")

if __name__ in "__main__":
main()
79 changes: 79 additions & 0 deletions cmd/e2e/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package main

import (
"log"
"net/http"
"os"

"github.com/GSA-TTS/jemison/internal/common"
"github.com/GSA-TTS/jemison/internal/env"
"github.com/GSA-TTS/jemison/internal/postgres"
"github.com/GSA-TTS/jemison/internal/queueing"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)

var ThisServiceName = "e2e"
var ChQSHP = make(chan queueing.QSHP)

var JDB *postgres.JemisonDB

func main() {
env.InitGlobalEnv(ThisServiceName)
s, _ := env.Env.GetUserService(ThisServiceName)

// For the heartbeat
engine := common.InitializeAPI()

template_files_path := s.GetParamString("template_files_path")
static_files_path := s.GetParamString("static_files_path")

// For the index template
// This provides links to the HTML files
// in the static directory.
engine.LoadHTMLGlob(template_files_path + "/*")

base_params := gin.H{
"scheme": "http",
"search_host": "e2e.gov",
"search_port": env.Env.Port,
}

files, err := os.ReadDir(static_files_path)
if err != nil {
log.Fatal(err)
}

filenames := make([]string, 0)
for _, file := range files {
if !file.IsDir() {
filenames = append(filenames, file.Name())
}
}

engine.GET("/www", func(c *gin.Context) {
// d64_start, _ := strconv.ParseInt("010000DD00000000", 16, 64)
// d64_end, _ := strconv.ParseInt("010000DDFFFFFF00", 16, 64)
// base_params["d64_start"] = d64_start
// base_params["d64_end"] = d64_end
base_params["filenames"] = filenames
c.HTML(http.StatusOK, "index.tmpl", base_params)
})

engine.HEAD("/www", func(c *gin.Context) {
// c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
base_params["filenames"] = filenames

c.HTML(http.StatusOK, "index.tmpl", base_params)
})

go queueing.Enqueue(ChQSHP)

zap.L().Info("listening to the music of the spheres",
zap.String("port", env.Env.Port))

engine.StaticFS("/static", gin.Dir(static_files_path, true))

go http.ListenAndServe(":80", engine)
http.ListenAndServe(":"+env.Env.Port, engine)
}
3 changes: 3 additions & 0 deletions cmd/e2e/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

/home/vcap/app/cmd/e2e/service.exe || exit 1
Loading
Loading