The website was a file built by hand outside the repository. It is now a template in internal/web: every gateway serves it at /about, without a key, linked from the landing page's footer, and the published site is rendered from the same template. The fonts are vendored (Latin subsets, OFL) so the page sends nobody's browser to Google. The proxy configurations it shows are copies of deploy/proxy, kept equal by a test. A development build says so instead of linking to release files that do not exist. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
package web
|
|
|
|
import (
|
|
"bytes"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestAboutPageForARelease(t *testing.T) {
|
|
code, body := get(t, About("v1.2.3"), "http://llmgw.example/about", nil)
|
|
if code != http.StatusOK {
|
|
t.Fatalf("status %d", code)
|
|
}
|
|
for _, want := range []string{
|
|
"<!doctype html>",
|
|
repoURL + "/releases/download/v1.2.3/llmgw-v1.2.3-linux-amd64",
|
|
"VERSION=v1.2.3",
|
|
"reverse_proxy", // the Caddyfile, inline
|
|
"proxy_read_timeout", // and nginx's
|
|
`<a href="/">This gateway</a>`,
|
|
"/_static/fonts/archivo-latin.woff2?v=",
|
|
} {
|
|
if !strings.Contains(body, want) {
|
|
t.Errorf("the page does not have %q", want)
|
|
}
|
|
}
|
|
// Served to anyone, on networks that may reach nothing: the page sends no
|
|
// browser elsewhere for its fonts, and does not announce unreleased work
|
|
// in a binary that already has it.
|
|
for _, not := range []string{"fonts.googleapis.com", "next release"} {
|
|
if strings.Contains(body, not) {
|
|
t.Errorf("the page has %q", not)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAboutPageForADevelopmentBuild(t *testing.T) {
|
|
_, body := get(t, About("v1.2.3-4-gabcdef"), "http://llmgw.example/about", nil)
|
|
if strings.Contains(body, "/releases/download/v1.2.3-4") || strings.Contains(body, `class="dl"`) {
|
|
t.Error("a development build links to release files that do not exist")
|
|
}
|
|
if !strings.Contains(body, "development build (v1.2.3-4-gabcdef)") {
|
|
t.Error("a development build does not say what it is")
|
|
}
|
|
}
|
|
|
|
func TestAboutPageAsTheWebsite(t *testing.T) {
|
|
d := NewAboutData("v1.2.3")
|
|
d.Site, d.Date = true, "1 January 2027"
|
|
var b bytes.Buffer
|
|
if err := RenderAbout(&b, d); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
body := b.String()
|
|
for _, want := range []string{"fonts.googleapis.com", "Released 1 January 2027", "next release"} {
|
|
if !strings.Contains(body, want) {
|
|
t.Errorf("the website does not have %q", want)
|
|
}
|
|
}
|
|
for _, not := range []string{"<!doctype", "</body>", "This gateway", "/_static/"} {
|
|
if strings.Contains(body, not) {
|
|
t.Errorf("the website has %q", not)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAboutProxyConfigsMatchDeploy(t *testing.T) {
|
|
for _, name := range []string{"Caddyfile", "nginx.conf"} {
|
|
want, err := os.ReadFile("../../deploy/proxy/" + name)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := proxyConfigs.ReadFile("proxy/" + name)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Equal(got, want) {
|
|
t.Errorf("internal/web/proxy/%s differs from deploy/proxy/%[1]s: copy it over", name)
|
|
}
|
|
}
|
|
}
|