From cbde69f6ee008db9c36dbf30f4da6344deebbb79 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 16 Oct 2024 23:00:26 +0200 Subject: [PATCH] Add test for ProtectedBranchRules.sort --- models/git/protected_banch_list_test.go | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/models/git/protected_banch_list_test.go b/models/git/protected_banch_list_test.go index 4bb3136d58..94a48f37e6 100644 --- a/models/git/protected_banch_list_test.go +++ b/models/git/protected_banch_list_test.go @@ -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) +}