Skip to content

bug: fix a flakey test #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions internal/cmd/match_criteria_test.go
Original file line number Diff line number Diff line change
@@ -166,7 +166,7 @@ func TestLabelsMatch(t *testing.T) {
}
}
func TestBranchMatchesCriteria(t *testing.T) {
t.Parallel()
// Remove t.Parallel() at the function level to avoid races on global variables

// Define test cases
tests := []struct {
@@ -263,10 +263,25 @@ func TestBranchMatchesCriteria(t *testing.T) {
}

for _, test := range tests {
test := test // Create a local copy of the test variable to use in the closure
t.Run(test.name, func(t *testing.T) {
t.Parallel()
t.Parallel() // Parallelize at the subtest level, each with their own local variables

// Save original values of global variables
origCombineBranchName := combineBranchName
origBranchPrefix := branchPrefix
origBranchSuffix := branchSuffix
origBranchRegex := branchRegex

// Restore original values after test
defer func() {
combineBranchName = origCombineBranchName
branchPrefix = origBranchPrefix
branchSuffix = origBranchSuffix
branchRegex = origBranchRegex
}()

// Set global variables for the test
// Set global variables for this specific test
combineBranchName = test.combineBranch
branchPrefix = test.prefix
branchSuffix = test.suffix
Loading
Oops, something went wrong.