v0.13.4 api update for deployment
test / test (push) Canceled after 0s

This commit is contained in:
lixen committed 2026-10-14 17:42:32 -04:00
1 parent ffbf603bc8
commit caf30df968
7 files changed
+89 -45

No files matched your search

+36
View File
@@ -2,7 +2,9 @@ package webserver
import (
"io/fs"
"strings"
"testing"
"testing/fstest"
)
func TestEmbeddedWebClientRoot(t *testing.T) {
@@ -20,3 +22,37 @@ func TestEmbeddedWebClientRoot(t *testing.T) {
}
}
}
func TestIndexHTMLSetsAPIBase(t *testing.T) {
content, err := fs.Sub(webFS, "chess-client-web")
if err != nil {
t.Fatal(err)
}
for apiURL, want := range map[string]string{
"http://localhost:8080": `<script src="app.js" data-api="http://localhost:8080">`,
`https://x.test/?a=1&b="2"`: `<script src="app.js" data-api="https://x.test/?a=1&amp;b=&#34;2&#34;">`,
} {
page, err := indexHTML(content, apiURL)
if err != nil {
t.Fatalf("%s: %v", apiURL, err)
}
if n := strings.Count(string(page), want); n != 1 {
t.Errorf("%s: index.html has %s %d times, want once", apiURL, want, n)
}
if strings.Contains(string(page), boardScript) {
t.Errorf("%s: index.html still loads the board without data-api", apiURL)
}
}
}
func TestIndexHTMLRefusesChangedScript(t *testing.T) {
for name, page := range map[string]string{
"absent": `<script src="./app.js"></script>`,
"twice": `<script src="app.js"></script><script src="app.js"></script>`,
} {
content := fstest.MapFS{"index.html": {Data: []byte(page)}}
if _, err := indexHTML(content, "http://localhost:8080"); err == nil {
t.Errorf("%s: no error", name)
}
}
}