| 54 | } |
| 55 | |
| 56 | func TestReady(t *testing.T) { |
| 57 | type testcase struct { |
| 58 | pr *PullRequest |
| 59 | cfg *config.Config |
| 60 | expect bool |
| 61 | } |
| 62 | |
| 63 | cfg := func(requireChecks bool, requireApproval bool) *config.Config { |
| 64 | return &config.Config{ |
| 65 | Repo: &config.RepoConfig{ |
| 66 | RequireChecks: requireChecks, |
| 67 | RequireApproval: requireApproval, |
| 68 | }, |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | pr := func(checks CheckStatus, wip bool, approved bool, noConflics bool, stacked bool) *PullRequest { |
| 73 | return &PullRequest{ |
| 74 | MergeStatus: PullRequestMergeStatus{ |
| 75 | ChecksPass: checks, |
| 76 | ReviewApproved: approved, |
| 77 | NoConflicts: noConflics, |
| 78 | Stacked: stacked, |
| 79 | }, |
| 80 | Commit: git.Commit{ |
| 81 | WIP: wip, |
| 82 | }, |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | tests := []testcase{ |
| 87 | {pr(CheckStatusUnknown, false, false, true, false), cfg(false, false), true}, |
| 88 | {pr(CheckStatusPass, false, true, true, false), cfg(true, false), true}, |
| 89 | {pr(CheckStatusPass, false, true, false, false), cfg(true, true), false}, |
| 90 | {pr(CheckStatusFail, false, false, false, false), cfg(true, true), false}, |
| 91 | {pr(CheckStatusPass, true, false, false, false), cfg(true, true), false}, |
| 92 | {pr(CheckStatusPass, false, true, false, false), cfg(true, true), false}, |
| 93 | {pr(CheckStatusPass, false, false, true, false), cfg(true, true), false}, |
| 94 | {pr(CheckStatusPass, false, false, false, true), cfg(true, true), false}, |
| 95 | } |
| 96 | for i, test := range tests { |
| 97 | assert.Equal(t, test.expect, test.pr.Ready(test.cfg), fmt.Sprintf("case %d failed", i)) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | func TestStatusString(t *testing.T) { |
| 102 | type testcase struct { |