Commit 7670a30c1b
Verified · cmc ci/build: success
Layout: unified · split
internal/httpd/buildpages_test.go added +80
| @@ -0,0 +1,80 @@ | |||
| 1 | package httpd | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "strings" | ||
| 5 | "testing" | ||
| 6 | |||
| 7 | "gitbay.org/gitbay/internal/store" | ||
| 8 | "gitbay.org/gitbay/internal/web" | ||
| 9 | ) | ||
| 10 | |||
| 11 | func testRepoPage() repoPage { | ||
| 12 | var p repoPage | ||
| 13 | p.Repo = store.Repo{OwnerName: "krz", Name: "gitbay", DefaultBranch: "main"} | ||
| 14 | p.Host = "gitbay.org" | ||
| 15 | return p | ||
| 16 | } | ||
| 17 | |||
| 18 | // The build pages read their data from the build commands' JSON now, not | ||
| 19 | // from store.Build. A renamed field would be a blank cell rather than a | ||
| 20 | // compile error, so render both pages and look for the values. | ||
| 21 | func TestBuildsPageRendersCommandOutput(t *testing.T) { | ||
| 22 | var sb strings.Builder | ||
| 23 | err := web.Render(&sb, "builds.html", struct { | ||
| 24 | repoPage | ||
| 25 | Builds []buildView | ||
| 26 | Jobs []jobView | ||
| 27 | CanWrite bool | ||
| 28 | Notice string | ||
| 29 | }{ | ||
| 30 | testRepoPage(), | ||
| 31 | []buildView{{ | ||
| 32 | Number: 60, Job: "build", Status: "success", | ||
| 33 | SHA: "ff6271a9d4570cd46f169091637a9d2e40ad5c2b", | ||
| 34 | Ref: "cli-coverage", CreatedAt: "2026-08-28T04:42:54Z", | ||
| 35 | }}, | ||
| 36 | []jobView{{Name: "build"}, {Name: "nightly", Schedule: "0 3 * * *"}}, | ||
| 37 | true, "", | ||
| 38 | }) | ||
| 39 | if err != nil { | ||
| 40 | t.Fatalf("render: %v", err) | ||
| 41 | } | ||
| 42 | out := sb.String() | ||
| 43 | for _, want := range []string{ | ||
| 44 | "#60 build", "success", "cli-coverage", "ff6271a9d4", | ||
| 45 | `value="build"`, `value="nightly"`, "schedule 0 3 * * *", | ||
| 46 | } { | ||
| 47 | if !strings.Contains(out, want) { | ||
| 48 | t.Errorf("builds.html missing %q", want) | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | func TestBuildPageRendersCommandOutput(t *testing.T) { | ||
| 54 | var sb strings.Builder | ||
| 55 | err := web.Render(&sb, "build.html", struct { | ||
| 56 | repoPage | ||
| 57 | Build buildView | ||
| 58 | Log string | ||
| 59 | }{ | ||
| 60 | testRepoPage(), | ||
| 61 | buildView{ | ||
| 62 | Number: 60, Job: "build", Status: "success", | ||
| 63 | SHA: "ff6271a9d4570cd46f169091637a9d2e40ad5c2b", Ref: "cli-coverage", | ||
| 64 | CreatedAt: "2026-08-28T04:42:54Z", FinishedAt: "2026-08-28T04:43:06Z", | ||
| 65 | }, | ||
| 66 | "step 1 ok", | ||
| 67 | }) | ||
| 68 | if err != nil { | ||
| 69 | t.Fatalf("render: %v", err) | ||
| 70 | } | ||
| 71 | out := sb.String() | ||
| 72 | for _, want := range []string{ | ||
| 73 | "Build 60", "success", "build on cli-coverage", "ff6271a9d4", | ||
| 74 | "2026-08-28 04:42", "2026-08-28 04:43", "step 1 ok", | ||
| 75 | } { | ||
| 76 | if !strings.Contains(out, want) { | ||
| 77 | t.Errorf("build.html missing %q", want) | ||
| 78 | } | ||
| 79 | } | ||
| 80 | } | ||