Skip to content

Commit cbde69f

Browse files
committed
Add test for ProtectedBranchRules.sort
1 parent 603fca1 commit cbde69f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

models/git/protected_banch_list_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,32 @@ func TestBranchRuleMatchPriority(t *testing.T) {
7474
}
7575
}
7676
}
77+
78+
func TestBranchRuleSort(t *testing.T) {
79+
in := []*ProtectedBranch{{
80+
RuleName: "b",
81+
CreatedUnix: 1,
82+
}, {
83+
RuleName: "b/*",
84+
CreatedUnix: 3,
85+
}, {
86+
RuleName: "a/*",
87+
CreatedUnix: 2,
88+
}, {
89+
RuleName: "c",
90+
CreatedUnix: 0,
91+
}, {
92+
RuleName: "a",
93+
CreatedUnix: 4,
94+
}}
95+
expect := []string{"c", "b", "a", "a/*", "b/*"}
96+
97+
pbr := ProtectedBranchRules(in)
98+
pbr.sort()
99+
100+
var got []string
101+
for i := range pbr {
102+
got = append(got, pbr[i].RuleName)
103+
}
104+
assert.Equal(t, expect, got)
105+
}

0 commit comments

Comments
 (0)