40 lines
1021 B
Go
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)
|
|
}
|
|
}
|