| 1 | package main |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | // An answer carries over landings only as far as the change's carry mode |
| 6 | // allows: same-paths over any, same-class over those that touched none |
| 7 | // of its classes, exact over none. |
| 8 | func TestCarryAllows(t *testing.T) { |
| 9 | for _, c := range []struct { |
| 10 | mode string |
| 11 | shared bool |
| 12 | want bool |
| 13 | }{ |
| 14 | {"same-paths", false, true}, |
| 15 | {"same-paths", true, true}, |
| 16 | {"same-class", false, true}, |
| 17 | {"same-class", true, false}, |
| 18 | {"exact", false, false}, |
| 19 | {"exact", true, false}, |
| 20 | {"unknown", false, false}, |
| 21 | } { |
| 22 | if got := carryAllows(c.mode, c.shared); got != c.want { |
| 23 | t.Errorf("carryAllows(%q, %v) = %v, want %v", c.mode, c.shared, got, c.want) |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | // A comparison that needs no carry mode is answered from the comparison |
| 29 | // alone: why the answer does not carry, and whether the later version is |
| 30 | // offered for approval at once, after the comparison is paged, or not. |
| 31 | func TestCarryVerdictReasons(t *testing.T) { |
| 32 | for _, c := range []struct { |
| 33 | c comparison |
| 34 | verdict, reason, offer string |
| 35 | }{ |
| 36 | {comparison{kind: compareNone}, "review", "it could not be set against v1", "none"}, |
| 37 | {comparison{kind: compareChanged, verb: "rebased", has: 1, had: 1, mainEdited: []string{"status/list.go"}}, |
| 38 | "review", "rebased onto main; its commit is unchanged, but main also edited 1 of its files (status/list.go)", "approve"}, |
| 39 | {comparison{kind: compareChanged, verb: "rebased", has: 2, had: 2, mainEdited: []string{"a", "b", "c", "d"}}, |
| 40 | "review", "rebased onto main; its 2 commits are unchanged, but main also edited 4 of its files (a, b, c, …)", "approve"}, |
| 41 | {comparison{kind: compareChanged, verb: "rebased", has: 1, had: 1, mainEdited: []string{"a\tb"}}, |
| 42 | "review", `rebased onto main; its commit is unchanged, but main also edited 1 of its files ("a\tb")`, "approve"}, |
| 43 | {comparison{kind: compareChanged, verb: "edited", edited: 1, has: 2, had: 2}, "review", "its commits changed (1 of 2)", "view"}, |
| 44 | {comparison{kind: compareChanged, verb: "edited", edited: 1, has: 1, had: 1}, "review", "its commit changed", "view"}, |
| 45 | {comparison{kind: compareChanged, verb: "edited", edited: 1, has: 2, had: 1}, |
| 46 | "review", "its commits changed (2 commits, where v1 had 1)", "view"}, |
| 47 | {comparison{kind: compareClean, meta: true, landings: []string{"b"}}, "review", "its commit messages or authors differ", "view"}, |
| 48 | {comparison{kind: compareClean, landings: []string{"b"}}, "carries", "v2 makes the same changes as v1 on the same main", ""}, |
| 49 | } { |
| 50 | verdict, reason, offer, err := carryVerdict(git{}, c.c, 1, 2, nil) |
| 51 | if err != nil || verdict != c.verdict || reason != c.reason || offer != c.offer { |
| 52 | t.Errorf("carryVerdict(%+v) = %q, %q, %q, %v; want %q, %q, %q", c.c, verdict, reason, offer, err, c.verdict, c.reason, c.offer) |
| 53 | } |
| 54 | } |
| 55 | } |