| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "reflect" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | // Main reads clear, clearing or muddy from the walk and the worker's runs: |
| 10 | // a failure, in a build or an evaluation, counts only when it is newer |
| 11 | // than the check's last pass. A landing is named by its change's handle, |
| 12 | // and a main commit without a change ID by its commit ID. |
| 13 | func TestMainLines(t *testing.T) { |
| 14 | c3, c2, c1 := "c3000000000", "c2000000000", "c1000000000" |
| 15 | walk := func(checks ...followCheck) mainWalk { |
| 16 | return mainWalk{checks: checks, walked: []string{c3, c2, c1}, tip: "t3", |
| 17 | trees: map[string]string{"t3": c3, "t2": c2, "t1": c1}, ids: map[string]string{c3: "kkkk", c2: ""}} |
| 18 | } |
| 19 | h := handleMap{{"app", recordTarget, "kkkk"}: "kk"} |
| 20 | e2e := nixCheck{"worker-e2e", "worker-e2e"} |
| 21 | due := followCheck{nixCheck: e2e, due: true, covers: []string{c3, c2}, passed: c1} |
| 22 | failedAt := func(tree string) []checkBuild { |
| 23 | return []checkBuild{{project: "app", check: "worker-e2e", tree: tree, result: "failed"}} |
| 24 | } |
| 25 | // A check that did not evaluate records no build time (attest/check.go). |
| 26 | page, _, err := parsePage(strings.NewReader(`{"kind":"record","type":"check.result","project":"app","tree":"t2",` + |
| 27 | `"check":"worker-e2e","data":{"result":"error","eval_ms":900}}` + "\n" + `{"kind":"end","cursor":""}` + "\n")) |
| 28 | if err != nil || len(page.builds) != 1 { |
| 29 | t.Fatalf("the page of a check that did not evaluate read as %v, %v", page.builds, err) |
| 30 | } |
| 31 | unevaluated := []checkBuild{page.builds[0].checkBuild} |
| 32 | running := []mainRun{{project: "app", tree: "t3", run: "r", checks: []string{"worker-e2e"}}} |
| 33 | term := terminal{width: 80} |
| 34 | for _, tc := range []struct { |
| 35 | name string |
| 36 | walk mainWalk |
| 37 | builds []checkBuild |
| 38 | runs []mainRun |
| 39 | want []string |
| 40 | }{ |
| 41 | {"passed", walk(followCheck{nixCheck: e2e, passed: c2}), nil, nil, |
| 42 | []string{"main ✓ clear · checks passed at c200000"}}, |
| 43 | {"due", walk(due), nil, nil, |
| 44 | []string{"main ◐ clearing · worker-e2e due · covers kk, c200000"}}, |
| 45 | {"running", walk(due), nil, running, |
| 46 | []string{"main ◐ clearing · worker-e2e running · covers kk, c200000"}}, |
| 47 | {"failed since its pass", walk(due), failedAt("t2"), nil, |
| 48 | []string{"main ✗ muddy · worker-e2e failed at c200000 · covers kk, c200000", |
| 49 | " see: valley telemetry read --source worker"}}, |
| 50 | {"did not evaluate", walk(due), unevaluated, nil, |
| 51 | []string{"main ✗ muddy · worker-e2e failed at c200000 · covers kk, c200000", |
| 52 | " see: valley telemetry read --source worker"}}, |
| 53 | {"failed before its pass", walk(due), failedAt("t1"), nil, |
| 54 | []string{"main ◐ clearing · worker-e2e due · covers kk, c200000"}}, |
| 55 | } { |
| 56 | if got := term.mainLines(tc.walk, "main ", "app", h, tc.builds, tc.runs); !reflect.DeepEqual(got, tc.want) { |
| 57 | t.Errorf("%s: got %q, want %q", tc.name, got, tc.want) |
| 58 | } |
| 59 | } |
| 60 | } |