Files
pages/tools/exhibition-demo/fixtures_test.go
T
Anya Tokugawa 4a863fe63c chore(exhibition): preserve deployment and synthetic demo tooling
Separate one-time bootstrap, historical deployment examples and local validation. Document final hostname and historical status; exclude credentials and runtime data.
2026-11-30 23:14:24 +09:00

98 lines
2.6 KiB
Go

package exhibitiondemo
import (
"archive/zip"
"io"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
ical "github.com/emersion/go-ical"
"pageswiki/internal/calendar"
"pageswiki/internal/render"
"pageswiki/internal/store"
)
// This test only generates local files and invokes parsers, never HTTP or a DB.
func TestGeneratedArtifactsWithApplicationParsers(t *testing.T) {
python, err := exec.LookPath("python3")
if err != nil {
t.Skip("optional application-parser integration requires python3; run the independent Python fixture tests before exhibition import")
}
out := filepath.Join(t.TempDir(), "demo")
command := exec.Command(python, "generate.py", "--base-date", "2026-11-15", "--output", out)
if result, err := command.CombinedOutput(); err != nil {
t.Fatalf("generate: %v\n%s", err, result)
}
read := func(name string) []byte {
t.Helper()
data, err := os.ReadFile(filepath.Join(out, name))
if err != nil {
t.Fatal(err)
}
return data
}
events, err := calendar.ParseFeed(read("calendar.ics"))
if err != nil || len(events) != 6 {
t.Fatalf("calendar feed: count=%d error=%v", len(events), err)
}
for _, folder := range []string{"contacts", "events", "tasks"} {
entries, err := os.ReadDir(filepath.Join(out, folder))
if err != nil {
t.Fatal(err)
}
for _, entry := range entries {
name := filepath.Join(folder, entry.Name())
data := string(read(name))
switch folder {
case "contacts":
if _, err := store.ParseContact(data); err != nil {
t.Errorf("%s: %v", name, err)
}
case "events":
if _, err := calendar.Parse(data); err != nil {
t.Errorf("%s: %v", name, err)
}
case "tasks":
value, err := ical.NewDecoder(strings.NewReader(data)).Decode()
if err != nil {
t.Fatalf("%s: %v", name, err)
}
if len(value.Children) != 1 || value.Children[0].Name != "VTODO" {
t.Errorf("%s: expected one VTODO", name)
}
}
}
}
archive, err := zip.OpenReader(filepath.Join(out, "wiki.zip"))
if err != nil {
t.Fatal(err)
}
defer archive.Close()
count := 0
for _, file := range archive.File {
if !strings.HasSuffix(file.Name, ".md") {
continue
}
reader, err := file.Open()
if err != nil {
t.Fatal(err)
}
data, err := io.ReadAll(reader)
reader.Close()
if err != nil {
t.Fatal(err)
}
html := render.Markdown(string(data))
if !strings.Contains(html, "<h1>") || !strings.Contains(html, "{{children:/exhibition-demo") || !strings.Contains(html, "href=\"/exhibition-demo/") {
t.Errorf("%s: expected heading, preserved macro and internal link", file.Name)
}
count++
}
if count != 26 {
t.Errorf("page count=%d", count)
}
}