initial commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user