From 9de68367de48d6adb594499ddfe774fd12355d6b Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Fri, 12 May 2023 12:59:56 +0200 Subject: [PATCH] refactor: simplify assets testing --- gateway/assets/README.md | 18 ++-- gateway/assets/build/main.go | 12 ++- gateway/assets/dag-index.html | 102 +++++++++++------------ gateway/assets/directory-index.html | 122 ++++++++++++++-------------- gateway/assets/error.html | 58 ++++++------- gateway/assets/test/main.go | 81 +++++++++--------- 6 files changed, 194 insertions(+), 199 deletions(-) diff --git a/gateway/assets/README.md b/gateway/assets/README.md index 25d1a35e8..e73b8ce9c 100644 --- a/gateway/assets/README.md +++ b/gateway/assets/README.md @@ -1,6 +1,6 @@ # Required Assets for the Gateway -> DAG and Directory HTML for HTTP gateway +> DAG, Directory and Error HTML for HTTP gateway ## Updating @@ -11,17 +11,13 @@ When making updates to the templates, please note the following: ## Testing -1. Make sure you have [Go](https://golang.org/dl/) installed -2. Start the test server, which lives in its own directory: +1. Make sure you have [Go](https://golang.org/dl/) installed. +2. From the `assets/` directory, start the test server: `go run test/main.go`. -```bash -> cd test -> go run . -``` - -This will listen on [`localhost:3000`](http://localhost:3000/) and reload the template every time you refresh the page. Here you have two pages: +This will listen on [`localhost:3000`](http://localhost:3000/) and reload the template every time you refresh the page. Here you have three pages: - [`localhost:3000/dag`](http://localhost:3000/dag) for the DAG template preview; and -- [`localhost:3000/directory`](http://localhost:3000/directory) for the Directory template preview. +- [`localhost:3000/directory`](http://localhost:3000/directory) for the Directory template preview; and +- [`localhost:3000/error?code=500`](http://localhost:3000/error?status=500) for the Error template preview, you can replace `500` by a different status code. -If you get a "no such file or directory" error upon trying `go run .`, make sure you ran `go generate .` to generate the minified artifact that the test is looking for. +Please make sure you run `go generate .` to generate the minified artifact that the test server is looking for every time you make a change. diff --git a/gateway/assets/build/main.go b/gateway/assets/build/main.go index 123ceff10..6f7ad3cda 100644 --- a/gateway/assets/build/main.go +++ b/gateway/assets/build/main.go @@ -5,10 +5,16 @@ import ( "os" ) +var templates = []string{ + "directory-index.html", + "dag-index.html", + "error.html", +} + func main() { - buildTemplate("directory-index.html") - buildTemplate("dag-index.html") - buildTemplate("error.html") + for _, tpl := range templates { + buildTemplate(tpl) + } } func loadStyles() []byte { diff --git a/gateway/assets/dag-index.html b/gateway/assets/dag-index.html index fd78b3592..912bad938 100644 --- a/gateway/assets/dag-index.html +++ b/gateway/assets/dag-index.html @@ -1,64 +1,64 @@ - - - - - - - - - - - - - - - -{{ .Path }} - + + + + + + + + + + + + + + + + {{ .Path }} + -