0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-28 22:48:13 +01:00

Add test for ProtectedBranchRules.sort

This commit is contained in:
6543 2024-10-16 23:00:26 +02:00
parent 603fca1e27
commit cbde69f6ee

View file

@ -74,3 +74,32 @@ func TestBranchRuleMatchPriority(t *testing.T) {
}
}
}
func TestBranchRuleSort(t *testing.T) {
in := []*ProtectedBranch{{
RuleName: "b",
CreatedUnix: 1,
}, {
RuleName: "b/*",
CreatedUnix: 3,
}, {
RuleName: "a/*",
CreatedUnix: 2,
}, {
RuleName: "c",
CreatedUnix: 0,
}, {
RuleName: "a",
CreatedUnix: 4,
}}
expect := []string{"c", "b", "a", "a/*", "b/*"}
pbr := ProtectedBranchRules(in)
pbr.sort()
var got []string
for i := range pbr {
got = append(got, pbr[i].RuleName)
}
assert.Equal(t, expect, got)
}