Skip to content

Commit 29636c7

Browse files
committed
fix flakey tests
1 parent 2000f7f commit 29636c7

File tree

2 files changed

+4
-26
lines changed

2 files changed

+4
-26
lines changed

internal/cmd/match_criteria.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// checks if a PR matches all filtering criteria
1616
func PrMatchesCriteria(branch string, prLabels []string) bool {
1717
// Check branch criteria if any are specified
18-
if !branchMatchesCriteria(branch) {
18+
if !branchMatchesCriteria(branch, combineBranchName, branchPrefix, branchSuffix, branchRegex) {
1919
return false
2020
}
2121

@@ -28,7 +28,7 @@ func PrMatchesCriteria(branch string, prLabels []string) bool {
2828
}
2929

3030
// checks if a branch matches the branch filtering criteria
31-
func branchMatchesCriteria(branch string) bool {
31+
func branchMatchesCriteria(branch, combineBranchName, branchPrefix, branchSuffix, branchRegex string) bool {
3232
Logger.Debug("Checking branch criteria", "branch", branch)
3333
// Do not attempt to match on existing branches that were created by this CLI
3434
if branch == combineBranchName {

internal/cmd/match_criteria_test.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ func TestLabelsMatch(t *testing.T) {
168168
}
169169
}
170170
func TestBranchMatchesCriteria(t *testing.T) {
171-
// Remove t.Parallel() at the function level to avoid races on global variables
172-
173171
// Define test cases
174172
tests := []struct {
175173
name string
@@ -269,28 +267,8 @@ func TestBranchMatchesCriteria(t *testing.T) {
269267
t.Run(test.name, func(t *testing.T) {
270268
t.Parallel() // Parallelize at the subtest level, each with their own local variables
271269

272-
// Save original values of global variables
273-
origCombineBranchName := combineBranchName
274-
origBranchPrefix := branchPrefix
275-
origBranchSuffix := branchSuffix
276-
origBranchRegex := branchRegex
277-
278-
// Restore original values after test
279-
defer func() {
280-
combineBranchName = origCombineBranchName
281-
branchPrefix = origBranchPrefix
282-
branchSuffix = origBranchSuffix
283-
branchRegex = origBranchRegex
284-
}()
285-
286-
// Set global variables for this specific test
287-
combineBranchName = test.combineBranch
288-
branchPrefix = test.prefix
289-
branchSuffix = test.suffix
290-
branchRegex = test.regex
291-
292-
// Run the function
293-
got := branchMatchesCriteria(test.branch)
270+
// Run the function
271+
got := branchMatchesCriteria(test.branch, test.combineBranch, test.prefix, test.suffix, test.regex)
294272

295273
// Check the result
296274
if got != test.want {

0 commit comments

Comments
 (0)