|
1 | 1 | package cmd
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "sync" |
4 | 5 | "testing"
|
5 | 6 | )
|
6 | 7 |
|
7 | 8 | func TestLabelsMatch(t *testing.T) {
|
8 |
| - t.Parallel() |
9 |
| - |
10 | 9 | tests := []struct {
|
11 | 10 | name string
|
12 | 11 | prLabels []string
|
@@ -147,19 +146,10 @@ func TestLabelsMatch(t *testing.T) {
|
147 | 146 | caseSensitive: true,
|
148 | 147 | },
|
149 | 148 | }
|
150 |
| - |
151 | 149 | for _, test := range tests {
|
152 | 150 | t.Run(test.name, func(t *testing.T) {
|
153 |
| - t.Parallel() |
154 |
| - |
155 |
| - // Save the original value of caseSensitiveLabels |
156 |
| - originalCaseSensitive := caseSensitiveLabels |
157 |
| - defer func() { caseSensitiveLabels = originalCaseSensitive }() // Restore after test |
158 | 151 |
|
159 |
| - // Set caseSensitiveLabels for this test |
160 |
| - caseSensitiveLabels = test.caseSensitive |
161 |
| - |
162 |
| - // Run the function |
| 152 | + // Run the function, passing the caseSensitive parameter directly |
163 | 153 | got := labelsMatch(test.prLabels, test.ignoreLabels, test.selectLabels, test.caseSensitive)
|
164 | 154 | if got != test.want {
|
165 | 155 | t.Errorf("Test %q failed: want %v, got %v", test.name, test.want, got)
|
@@ -356,24 +346,33 @@ func TestPrMatchesCriteriaWithMocks(t *testing.T) {
|
356 | 346 | }
|
357 | 347 |
|
358 | 348 | func TestPrMatchesCriteria(t *testing.T) {
|
| 349 | + // Since this test changes global state, don't use t.Parallel() |
| 350 | + |
| 351 | + // Create mutex to protect access to global variables |
| 352 | + var mutex sync.Mutex |
| 353 | + |
359 | 354 | // Save original values of global variables
|
| 355 | + mutex.Lock() |
360 | 356 | origIgnoreLabels := ignoreLabels
|
361 | 357 | origSelectLabels := selectLabels
|
362 | 358 | origCaseSensitiveLabels := caseSensitiveLabels
|
363 | 359 | origCombineBranchName := combineBranchName
|
364 | 360 | origBranchPrefix := branchPrefix
|
365 | 361 | origBranchSuffix := branchSuffix
|
366 | 362 | origBranchRegex := branchRegex
|
| 363 | + mutex.Unlock() |
367 | 364 |
|
368 | 365 | // Restore original values after test
|
369 | 366 | defer func() {
|
| 367 | + mutex.Lock() |
370 | 368 | ignoreLabels = origIgnoreLabels
|
371 | 369 | selectLabels = origSelectLabels
|
372 | 370 | caseSensitiveLabels = origCaseSensitiveLabels
|
373 | 371 | combineBranchName = origCombineBranchName
|
374 | 372 | branchPrefix = origBranchPrefix
|
375 | 373 | branchSuffix = origBranchSuffix
|
376 | 374 | branchRegex = origBranchRegex
|
| 375 | + mutex.Unlock() |
377 | 376 | }()
|
378 | 377 |
|
379 | 378 | // Test cases
|
|
0 commit comments