Files
summercms/cmd/summer/docs_test.go
Jakub Zych 6dacddc040 feat(11.1-01): add summer docs:build with the docsite generator core
- internal/docsite loads docs/ with strict site.yaml and frontmatter decoding
- goldmark GFM pipeline renders pages into an embedded html/template shell
- emits .html pages, .md siblings, llms.txt, llms-full.txt, search-index.json
- output guard refuses unmarked non-empty dirs and --out inside --src or root
- docs/index.md and docs/setup/installation.md; /site/ is gitignored
2026-09-30 21:18:32 +02:00

60 lines
1.5 KiB
Go

package main
import (
"bytes"
"os"
"path/filepath"
"regexp"
"testing"
"git.golem15.com/golem15/summercms/internal/docsite"
"git.golem15.com/golem15/summercms/modules/bonfire"
)
const repoRoot = "../.."
// TestDocsTree fails with every problem line in the real docs tree.
func TestDocsTree(t *testing.T) {
problems, err := docsite.Check(docsite.Options{Root: repoRoot})
if err != nil {
t.Fatal(err)
}
for _, p := range problems {
t.Error(p.String())
}
}
// buildRealTree runs docs:build on the real tree into a temp dir and returns
// the output dir and the command output.
func buildRealTree(t *testing.T) (string, string) {
t.Helper()
out := filepath.Join(t.TempDir(), "site")
var buf bytes.Buffer
root, err := bonfire.NewRoot("summer", toolCommands(), &buf)
if err != nil {
t.Fatal(err)
}
root.SetArgs([]string{"docs:build", "--root", repoRoot, "--out", out})
if err := root.Execute(); err != nil {
t.Fatalf("docs:build: %v\n%s", err, buf.String())
}
return out, buf.String()
}
func TestDocsBuildRealTree(t *testing.T) {
out, stdout := buildRealTree(t)
if !regexp.MustCompile(`docs:build: wrote \d+ pages to `).MatchString(stdout) {
t.Fatalf("output = %q, want a wrote-pages line", stdout)
}
for _, name := range []string{
"index.html", "index.md",
"setup/installation.html", "setup/installation.md",
"llms.txt", "llms-full.txt", "search-index.json",
"assets/site.css", docsite.MarkerFile,
} {
if _, err := os.Stat(filepath.Join(out, name)); err != nil {
t.Errorf("missing %s: %v", name, err)
}
}
}