mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 12:59:11 -05:00
ac2e882dbf
Close #29628 rule ``` Test / Build* Test / Build * Test / Build 2* Test / Build 1* ``` ![image](https://github.com/go-gitea/gitea/assets/30816317/19bef0a9-fa97-43c5-887b-dece76064aa8) rule2 ``` Test / Build* Test / Build 1* ``` ![image](https://github.com/go-gitea/gitea/assets/30816317/19bef0a9-fa97-43c5-887b-dece76064aa8) rule3 ``` Test / Build* Test / Build 1* NotExist* ``` ![image](https://github.com/go-gitea/gitea/assets/30816317/f6a5e832-2e1b-4049-915b-45bec5ef070c) --------- Co-authored-by: Zettat123 <zettat123@gmail.com> (cherry picked from commit 7cf7a499be80931ae34588201e9605085898e9b8)
65 lines
1.9 KiB
Go
65 lines
1.9 KiB
Go
// Copyright 2024 The Gitea Authors.
|
|
// All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package pull
|
|
|
|
import (
|
|
"testing"
|
|
|
|
git_model "code.gitea.io/gitea/models/git"
|
|
"code.gitea.io/gitea/modules/structs"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMergeRequiredContextsCommitStatus(t *testing.T) {
|
|
testCases := [][]*git_model.CommitStatus{
|
|
{
|
|
{Context: "Build 1", State: structs.CommitStatusSuccess},
|
|
{Context: "Build 2", State: structs.CommitStatusSuccess},
|
|
{Context: "Build 3", State: structs.CommitStatusSuccess},
|
|
},
|
|
{
|
|
{Context: "Build 1", State: structs.CommitStatusSuccess},
|
|
{Context: "Build 2", State: structs.CommitStatusSuccess},
|
|
{Context: "Build 2t", State: structs.CommitStatusPending},
|
|
},
|
|
{
|
|
{Context: "Build 1", State: structs.CommitStatusSuccess},
|
|
{Context: "Build 2", State: structs.CommitStatusSuccess},
|
|
{Context: "Build 2t", State: structs.CommitStatusFailure},
|
|
},
|
|
{
|
|
{Context: "Build 1", State: structs.CommitStatusSuccess},
|
|
{Context: "Build 2", State: structs.CommitStatusSuccess},
|
|
{Context: "Build 2t", State: structs.CommitStatusSuccess},
|
|
},
|
|
{
|
|
{Context: "Build 1", State: structs.CommitStatusSuccess},
|
|
{Context: "Build 2", State: structs.CommitStatusSuccess},
|
|
{Context: "Build 2t", State: structs.CommitStatusSuccess},
|
|
},
|
|
}
|
|
testCasesRequiredContexts := [][]string{
|
|
{"Build*"},
|
|
{"Build*", "Build 2t*"},
|
|
{"Build*", "Build 2t*"},
|
|
{"Build*", "Build 2t*", "Build 3*"},
|
|
{"Build*", "Build *", "Build 2t*", "Build 1*"},
|
|
}
|
|
|
|
testCasesExpected := []structs.CommitStatusState{
|
|
structs.CommitStatusSuccess,
|
|
structs.CommitStatusPending,
|
|
structs.CommitStatusFailure,
|
|
structs.CommitStatusPending,
|
|
structs.CommitStatusSuccess,
|
|
}
|
|
|
|
for i, commitStatuses := range testCases {
|
|
if MergeRequiredContextsCommitStatus(commitStatuses, testCasesRequiredContexts[i]) != testCasesExpected[i] {
|
|
assert.Fail(t, "Test case failed", "Test case %d failed", i+1)
|
|
}
|
|
}
|
|
}
|