vole
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software:2222/vole.git
A free and open-source forge that lives in your Git repo.
Expand the admin status page into an operational dashboard
4506a4d3d279556435fdd414265e7499c3dada16 · Keenan Nemetz · 14d ago · parent 2e024cc9
server/runners_page_test.go +16−39
| @@ -6,6 +6,7 @@ package server_test | |||
| 6 | 6 | // about a process on somebody else's machine. | |
| 7 | 7 | ||
| 8 | 8 | import ( | |
| 9 | "net/http" | ||
| 9 | 10 | "strings" | |
| 10 | 11 | "testing" | |
| 11 | 12 | "time" | |
| @@ -23,7 +24,7 @@ func queuedRun(id, repo, job string, created time.Time) runs.Run { | |||
| 23 | 24 | } | |
| 24 | 25 | } | |
| 25 | 26 | ||
| 26 | func TestRunnersPageShowsTheRunnerHoldingAJobAndTheQueueDepth(t *testing.T) { | ||
| 27 | func TestStatusPageShowsTheRunnerHoldingAJobAndTheQueueDepth(t *testing.T) { | ||
| 27 | 28 | t.Parallel() | |
| 28 | 29 | f := newFixture(t) | |
| 29 | 30 | f.publish(f.repo) | |
| @@ -46,9 +47,9 @@ func TestRunnersPageShowsTheRunnerHoldingAJobAndTheQueueDepth(t *testing.T) { | |||
| 46 | 47 | t.Fatal(err) | |
| 47 | 48 | } | |
| 48 | 49 | ||
| 49 | code, body := f.get("/runners") | ||
| 50 | code, body := f.adminGet(t, "/status?tab=runners") | ||
| 50 | 51 | if code != 200 { | |
| 51 | t.Fatalf("GET /runners = %d\n%s", code, body) | ||
| 52 | t.Fatalf("GET /status?tab=runners = %d\n%s", code, body) | ||
| 52 | 53 | } | |
| 53 | 54 | for _, want := range []string{ | |
| 54 | 55 | "keenan", // the account the key resolved to | |
| @@ -72,7 +73,7 @@ func TestRunnersPageShowsTheRunnerHoldingAJobAndTheQueueDepth(t *testing.T) { | |||
| 72 | 73 | // A repository at its per-repository cap is the case where a waiting job has a | |
| 73 | 74 | // reason, and the page is where that reason has to be readable: "7 waiting, 4 running" | |
| 74 | 75 | // is a mystery, "4 of 4 (at the cap)" is not. | |
| 75 | func TestRunnersPageSaysWhenARepositoryIsAtItsCap(t *testing.T) { | ||
| 76 | func TestStatusPageSaysWhenARepositoryIsAtItsCap(t *testing.T) { | ||
| 76 | 77 | t.Parallel() | |
| 77 | 78 | f := newFixtureWith(t, func(c *config.Config) { c.MaxJobsPerRepo = 1 }) | |
| 78 | 79 | f.publish(f.repo) | |
| @@ -92,55 +93,31 @@ func TestRunnersPageSaysWhenARepositoryIsAtItsCap(t *testing.T) { | |||
| 92 | 93 | t.Fatal(err) | |
| 93 | 94 | } | |
| 94 | 95 | ||
| 95 | code, body := f.get("/runners") | ||
| 96 | code, body := f.adminGet(t, "/status?tab=runners") | ||
| 96 | 97 | if code != 200 { | |
| 97 | t.Fatalf("GET /runners = %d\n%s", code, body) | ||
| 98 | t.Fatalf("GET /status?tab=runners = %d\n%s", code, body) | ||
| 98 | 99 | } | |
| 99 | 100 | if !strings.Contains(body, "1 of 1") || !strings.Contains(body, "at the cap") { | |
| 100 | 101 | t.Fatalf("the page does not say the repository is at its cap of 1:\n%s", body) | |
| 101 | 102 | } | |
| 102 | 103 | } | |
| 103 | 104 | ||
| 104 | func TestRunnersPageKeepsAPrivateRepositoryOut(t *testing.T) { | ||
| 105 | func TestRunnersRedirectsToStatus(t *testing.T) { | ||
| 105 | 106 | t.Parallel() | |
| 106 | 107 | f := newFixture(t) | |
| 107 | f.publish(f.repo) | ||
| 108 | now := time.Now().UTC() | ||
| 109 | f.addWriter(t) // wilbur, who may write the public repo and nothing else | ||
| 110 | |||
| 111 | secret, err := f.srv.Repos.Create("secret", f.ownerID, "not published") | ||
| 112 | if err != nil { | ||
| 113 | t.Fatal(err) | ||
| 114 | } | ||
| 115 | if err := f.srv.Index.Upsert(secret); err != nil { | ||
| 116 | t.Fatal(err) | ||
| 117 | } | ||
| 118 | private := queuedRun("01PRIVATERUN00000000000000", "secret", "private-job", now) | ||
| 119 | if _, err := f.srv.Runs.Enqueue(private, nil); err != nil { | ||
| 120 | t.Fatal(err) | ||
| 108 | resp, _ := f.browserGet(t, "/runners", "") | ||
| 109 | if resp.StatusCode != http.StatusMovedPermanently { | ||
| 110 | t.Fatalf("GET /runners = %d, want a redirect", resp.StatusCode) | ||
| 121 | 111 | } | |
| 122 | if err := f.srv.Runs.TouchSession("session-private", f.writerID, nil, now); err != nil { | ||
| 123 | t.Fatal(err) | ||
| 124 | } | ||
| 125 | if err := f.srv.Runs.SessionWorking("session-private", "secret", private.ID, now); err != nil { | ||
| 126 | t.Fatal(err) | ||
| 127 | } | ||
| 128 | |||
| 129 | code, body := f.get("/runners") | ||
| 130 | if code != 200 { | ||
| 131 | t.Fatalf("GET /runners = %d\n%s", code, body) | ||
| 132 | } | ||
| 133 | for _, hidden := range []string{"secret", "wilbur", private.ID, private.Job} { | ||
| 134 | if strings.Contains(body, hidden) { | ||
| 135 | t.Errorf("the runners page shows %q, which belongs to a private repository:\n%s", hidden, body) | ||
| 136 | } | ||
| 112 | if got := resp.Header.Get("Location"); got != "/status?tab=runners" { | ||
| 113 | t.Fatalf("GET /runners redirected to %q", got) | ||
| 137 | 114 | } | |
| 138 | 115 | } | |
| 139 | 116 | ||
| 140 | 117 | // A job waiting for a machine that is not connected is invisible from the queue side: | |
| 141 | 118 | // the depth says one is waiting, and nothing says why nobody took it. The runner's own | |
| 142 | 119 | // labels are the missing half, so the page shows them next to the agent. | |
| 143 | func TestRunnersPageShowsWhatEachRunnerTakes(t *testing.T) { | ||
| 120 | func TestStatusPageShowsWhatEachRunnerTakes(t *testing.T) { | ||
| 144 | 121 | t.Parallel() | |
| 145 | 122 | f := newFixture(t) | |
| 146 | 123 | f.publish(f.repo) | |
| @@ -153,9 +130,9 @@ func TestRunnersPageShowsWhatEachRunnerTakes(t *testing.T) { | |||
| 153 | 130 | t.Fatal(err) | |
| 154 | 131 | } | |
| 155 | 132 | ||
| 156 | code, body := f.get("/runners") | ||
| 133 | code, body := f.adminGet(t, "/status?tab=runners") | ||
| 157 | 134 | if code != 200 { | |
| 158 | t.Fatalf("GET /runners = %d\n%s", code, body) | ||
| 135 | t.Fatalf("GET /status?tab=runners = %d\n%s", code, body) | ||
| 159 | 136 | } | |
| 160 | 137 | if !strings.Contains(body, "linux, arm64") { | |
| 161 | 138 | t.Fatalf("the page does not show the labels a runner carries:\n%s", body) | |