|
| 1 | +package pull |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + git_model "code.gitea.io/gitea/models/git" |
| 7 | + "code.gitea.io/gitea/modules/structs" |
| 8 | + "github.com/stretchr/testify/assert" |
| 9 | +) |
| 10 | + |
| 11 | +func TestMergeRequiredContextsCommitStatus(t *testing.T) { |
| 12 | + testCases := [][]*git_model.CommitStatus{ |
| 13 | + { |
| 14 | + {Context: "Build 1", State: structs.CommitStatusSuccess}, |
| 15 | + {Context: "Build 2", State: structs.CommitStatusSuccess}, |
| 16 | + {Context: "Build 3", State: structs.CommitStatusSuccess}, |
| 17 | + }, |
| 18 | + { |
| 19 | + {Context: "Build 1", State: structs.CommitStatusSuccess}, |
| 20 | + {Context: "Build 2", State: structs.CommitStatusSuccess}, |
| 21 | + {Context: "Build 2t", State: structs.CommitStatusPending}, |
| 22 | + }, |
| 23 | + { |
| 24 | + {Context: "Build 1", State: structs.CommitStatusSuccess}, |
| 25 | + {Context: "Build 2", State: structs.CommitStatusSuccess}, |
| 26 | + {Context: "Build 2t", State: structs.CommitStatusFailure}, |
| 27 | + }, |
| 28 | + { |
| 29 | + {Context: "Build 1", State: structs.CommitStatusSuccess}, |
| 30 | + {Context: "Build 2", State: structs.CommitStatusSuccess}, |
| 31 | + {Context: "Build 2t", State: structs.CommitStatusSuccess}, |
| 32 | + }, |
| 33 | + } |
| 34 | + testCasesRequiredContexts := [][]string{ |
| 35 | + {"Build*"}, |
| 36 | + {"Build*", "Build 2t*"}, |
| 37 | + {"Build*", "Build 2t*"}, |
| 38 | + {"Build*", "Build 2t*", "Build 3*"}, |
| 39 | + } |
| 40 | + |
| 41 | + testCasesExpected := []structs.CommitStatusState{ |
| 42 | + structs.CommitStatusSuccess, |
| 43 | + structs.CommitStatusPending, |
| 44 | + structs.CommitStatusFailure, |
| 45 | + structs.CommitStatusPending, |
| 46 | + } |
| 47 | + |
| 48 | + for i, commitStatuses := range testCases { |
| 49 | + if MergeRequiredContextsCommitStatus(commitStatuses, testCasesRequiredContexts[i]) != testCasesExpected[i] { |
| 50 | + assert.Fail(t, "Test case failed", "Test case %d failed", i+1) |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments