package sites import ( "context" "os" "os/exec" "path/filepath" "strings" "testing" "supermarket/internal/hugorepo" ) func TestNewSiteFiles(t *testing.T) { n := Defaults() n.Repo, n.URL, n.Title, n.Tagline, n.Email = " https://gitea.example/Us/acme.git ", "https://www.acme.example/", `Acme "Widgets" & Co`, "Wïdgets, for everyone", "hi@acme.example" if err := n.Check(); err != nil { t.Fatal(err) } if n.Repo != "Us/acme" || n.URL != "https://www.acme.example" { t.Errorf("tidied: %+v", n) } f := n.Files() if !strings.Contains(f["hugo.toml"], `title = "Acme \"Widgets\" & Co"`) { t.Errorf("hugo.toml:\n%s", f["hugo.toml"]) } // Hugo reads the settings and builds the site, the title as given. if _, err := exec.LookPath("hugo"); err == nil { dir := t.TempDir() for rel, body := range f { os.MkdirAll(filepath.Join(dir, filepath.Dir(rel)), 0o755) os.WriteFile(filepath.Join(dir, rel), []byte(body), 0o644) } out, err := hugorepo.BuildDir(context.Background(), dir) if err != nil { t.Fatal(err) } defer os.RemoveAll(out) home, _ := os.ReadFile(filepath.Join(out, "index.html")) if !strings.Contains(string(home), "