Files
helix-proxy/internal/www/page_test.go
T
s1d3sw1ped 1cc94f2c99
Format / gofmt (push) Failing after 27s
CI / Build (push) Successful in 51s
CI / Go Tests (push) Failing after 21s
initial commit
2026-06-06 07:54:44 -05:00

40 lines
1021 B
Go

package www
import (
"os"
"path/filepath"
"strings"
"testing"
"helix-proxy/internal/config"
)
func TestLoadPageEmbeddedDefault(t *testing.T) {
t.Setenv("DATA_DIR", t.TempDir())
page := LoadPage("index.html", map[string]string{"HOST": "test.example"})
if page == nil {
t.Fatal("expected embedded index.html")
}
body := string(page)
if !strings.Contains(body, "test.example") || !strings.Contains(body, "Welcome to Helix Proxy") {
t.Fatalf("unexpected page: %s", page)
}
}
func TestLoadPageWWWOverride(t *testing.T) {
dir := t.TempDir()
t.Setenv("DATA_DIR", dir)
wwwDir := config.Resolve("www")
if err := os.MkdirAll(wwwDir, 0o755); err != nil {
t.Fatal(err)
}
custom := []byte("<h1>CUSTOM {{HOST}}</h1>")
if err := os.WriteFile(filepath.Join(wwwDir, "index.html"), custom, 0o644); err != nil {
t.Fatal(err)
}
page := LoadPage("index.html", map[string]string{"HOST": "override.example"})
if string(page) != "<h1>CUSTOM override.example</h1>" {
t.Fatalf("override failed: %q", page)
}
}