Skip to content

Commit b4c97d6

Browse files
committed
updated tests
1 parent 2e81806 commit b4c97d6

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

internal/cmd/match_criteria_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,80 @@ func TestBranchMatchesCriteria(t *testing.T) {
228228
})
229229
}
230230
}
231+
232+
func prMatchesCriteriaWithMocks(branch string, prLabels []string, branchMatches func(string) bool, labelsMatch func([]string, []string, []string) bool) bool {
233+
return branchMatches(branch) && labelsMatch(prLabels, nil, nil)
234+
}
235+
236+
func TestPrMatchesCriteriaWithMocks(t *testing.T) {
237+
t.Parallel()
238+
239+
tests := []struct {
240+
name string
241+
branch string
242+
prLabels []string
243+
branchPass bool
244+
labelsPass bool
245+
want bool
246+
}{
247+
{
248+
name: "Branch and labels match",
249+
branch: "feature/test",
250+
prLabels: []string{"bug", "enhancement"},
251+
branchPass: true,
252+
labelsPass: true,
253+
want: true,
254+
},
255+
{
256+
name: "Branch does not match",
257+
branch: "hotfix/test",
258+
prLabels: []string{"bug", "enhancement"},
259+
branchPass: false,
260+
labelsPass: true,
261+
want: false,
262+
},
263+
{
264+
name: "Labels do not match",
265+
branch: "feature/test",
266+
prLabels: []string{"wip"},
267+
branchPass: true,
268+
labelsPass: false,
269+
want: false,
270+
},
271+
{
272+
name: "Neither branch nor labels match",
273+
branch: "hotfix/test",
274+
prLabels: []string{"wip"},
275+
branchPass: false,
276+
labelsPass: false,
277+
want: false,
278+
},
279+
{
280+
name: "No branch or label filters specified",
281+
branch: "any-branch",
282+
prLabels: []string{},
283+
branchPass: true,
284+
labelsPass: true,
285+
want: true,
286+
},
287+
}
288+
289+
for _, test := range tests {
290+
t.Run(test.name, func(t *testing.T) {
291+
t.Parallel()
292+
293+
// Mock branchMatchesCriteria and labelsMatch
294+
mockBranchMatchesCriteria := func(branch string) bool {
295+
return test.branchPass
296+
}
297+
mockLabelsMatch := func(prLabels []string, ignoreLabels []string, selectLabels []string) bool {
298+
return test.labelsPass
299+
}
300+
301+
got := prMatchesCriteriaWithMocks(test.branch, test.prLabels, mockBranchMatchesCriteria, mockLabelsMatch)
302+
if got != test.want {
303+
t.Errorf("PrMatchesCriteria(%q, %v) = %v; want %v", test.branch, test.prLabels, got, test.want)
304+
}
305+
})
306+
}
307+
}

0 commit comments

Comments
 (0)