|
|
@@ -304,6 +304,52 @@ func TestHeaderAndFooter(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func TestAboutCommitLink(t *testing.T) {
|
|
|
+ const full = "d2a387e186c8caf21a35349b8c3d60f68fb87b1f"
|
|
|
+ about := func(t *testing.T, c commitInfo, siteJSON string) string {
|
|
|
+ t.Helper()
|
|
|
+ dir := t.TempDir()
|
|
|
+ if siteJSON != "" {
|
|
|
+ writeFile(t, dir, "site.json", siteJSON)
|
|
|
+ }
|
|
|
+ a, err := newApp(dir, "https://posts.example.com")
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ a.commit = c // go test binaries carry no VCS stamp; set one
|
|
|
+ srv := httptest.NewServer(a.routes())
|
|
|
+ t.Cleanup(srv.Close)
|
|
|
+ _, _, body := get(t, srv, "/about")
|
|
|
+ return body
|
|
|
+ }
|
|
|
+
|
|
|
+ t.Run("clean build links the full hash", func(t *testing.T) {
|
|
|
+ body := about(t, commitInfo{Full: full, Short: full[:7]}, "")
|
|
|
+ want := `<span class="muted">(<a href="https://git.monoaf.com/bajdev/posts/commit/` + full + `">d2a387e</a>)</span>`
|
|
|
+ if !strings.Contains(body, want) {
|
|
|
+ t.Errorf("missing %s in:\n%s", want, body)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ t.Run("repoURL from site.json", func(t *testing.T) {
|
|
|
+ body := about(t, commitInfo{Full: full, Short: full[:7]}, `{"repoURL": "https://example.org/me/fork/"}`)
|
|
|
+ if !strings.Contains(body, `href="https://example.org/me/fork/commit/`+full+`"`) {
|
|
|
+ t.Errorf("site.json repoURL not used:\n%s", body)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ t.Run("dirty build is not linked", func(t *testing.T) {
|
|
|
+ body := about(t, commitInfo{Full: full, Short: full[:7], Dirty: true}, "")
|
|
|
+ if !strings.Contains(body, `(d2a387e-dirty)`) || strings.Contains(body, "/commit/") {
|
|
|
+ t.Errorf("dirty build should show -dirty with no link:\n%s", body)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ t.Run("no commit shows version only", func(t *testing.T) {
|
|
|
+ body := about(t, commitInfo{}, "")
|
|
|
+ if !strings.Contains(body, "<dd>"+version+"</dd>") {
|
|
|
+ t.Errorf("want bare version:\n%s", body)
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
func TestAboutPage(t *testing.T) {
|
|
|
srv, _ := newTestServer(t, sample)
|
|
|
status, _, body := get(t, srv, "/about")
|