@@ -2,6 +2,7 @@ package site
22
33 import (
44 "os"
5+ "os/exec"
56 "path/filepath"
67 "strings"
78 "testing"
@@ -9,9 +10,30 @@ import (
910 "xonecas.io/site/internal/project"
1011 )
1112
13+// gitRepo makes a repo with a README that links a doc and shows an image, and returns its git dir.
14+func gitRepo(t *testing.T) string {
15+ dir := t.TempDir()
16+ files := map[string]string{
17+ "README.md": "#Hello\n\n [docs](docs/) [guide](docs/guide.md#top) [web](https://x.io)\n",
18+ "img/logo.png": "\x89PNG\x00\n",
19+ "docs/guide.md": "guide\n",
20+ }
21+ for f, body := range files {
22+ os.MkdirAll(filepath.Join(dir, filepath.Dir(f)), 0o755)
23+ os.WriteFile(filepath.Join(dir, f), []byte(body), 0o644)
24+ }
25+ for _, args := range [][]string{{"init", "-q"}, {"add", "."}, {"-c", "user.name=xonecas", "-c", "user.email=x@x", "commit", "-qm", "first"}} {
26+ if out, err := exec.Command("git", append([]string{"-C", dir}, args...)...).CombinedOutput(); err != nil {
27+ t.Fatal(string(out))
28+ }
29+ }
30+ return filepath.Join(dir, ".git")
31+}
32+
1233 func TestBuild(t *testing.T) {
34+ src := []project.Source{{URL: "https://github.com/xonecas/hello.git", Dir: gitRepo(t), Branch: "main"}}
1335 projects := []project.Project{
14- {Name: "hello", Info: project.Info{Commits: 3, First: "2026-10-01", Last: "2026-11-01", Description: "says hi", Tags: []string{"pre-AI", "small", "frontend"}}},
36+ {Name: "hello", Sources: src, Info: project.Info{Readme: "README.md", Commits: 3, First: "2026-10-01", Last: "2026-11-01", Description: "says hi", Tags: []string{"pre-AI", "small", "frontend"}}},
1537 {Name: "a-fork", Info: project.Info{Hidden: "fork"}},
1638 }
1739 out := t.TempDir()
@@ -42,7 +64,17 @@ func TestBuild(t *testing.T) {
4264 if strings.Contains(string(page), "a-fork") {
4365 t.Error("projects/index.html lists a hidden project")
4466 }
45- for _, f := range []string{"style/index.html", "logo.svg", "projects.js"} {
67+ page, err = os.ReadFile(filepath.Join(out, "projects/hello/index.html"))
68+ if err != nil {
69+ t.Fatal(err)
70+ }
71+ for _, want := range []string{`<h1 id="hello">Hello</h1>`, `src="/projects/hello/raw/img/logo.png"`, `href="/projects/hello/tree/docs/"`,
72+ `href="/projects/hello/blob/docs/guide.md/#top"`, `href="https://x.io"`, `git clone https://github.com/xonecas/hello.git`} {
73+ if !strings.Contains(string(page), want) {
74+ t.Errorf("projects/hello/index.html is missing %q", want)
75+ }
76+ }
77+ for _, f := range []string{"style/index.html", "logo.svg", "projects.js", "projects/hello/raw/img/logo.png"} {
4678 if _, err := os.Stat(filepath.Join(out, f)); err != nil {
4779 t.Error(err)
4880 }