Skip to content

Commit ad48e08

Browse files
committed
fix(lint): satisfy wsl_v5/testifylint/paralleltest in opa download_policy
1 parent 44f5ad0 commit ad48e08

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

modules/opa/download_policy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,14 @@ func DownloadPolicyE(t testing.TestingT, rulePath string) (string, error) {
6969
if downloadPath, hasDownloaded := policyDirCache.Load(baseDir); hasDownloaded {
7070
return downloadPath.(string), nil
7171
}
72+
7273
tempDir, err := downloadPolicyToTempDir(t, rulePath, baseDir)
7374
if err != nil {
7475
return "", err
7576
}
77+
7678
policyDirCache.Store(baseDir, tempDir)
79+
7780
return tempDir, nil
7881
})
7982
if err != nil {

modules/opa/download_policy_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,19 @@ func TestDownloadPolicyDownloadsRemote(t *testing.T) {
6767

6868
// TestDownloadPolicyDeduplicatesConcurrentDownloads makes sure concurrent calls for the same rulePath collapse to a
6969
// single cache entry rather than racing into separate temp directories.
70+
//
71+
//nolint:paralleltest // go-getter's Client.configure has an internal race on its global Getters map, so we cannot run alongside other go-getter tests.
7072
func TestDownloadPolicyDeduplicatesConcurrentDownloads(t *testing.T) {
71-
// Not Parallel: go-getter's Client.configure has an internal race on its global Getters map, so we don't run this
72-
// alongside other tests that also invoke go-getter.
7373
baseDir := "git::https://github.com/gruntwork-io/terratest.git?ref=v0.50.0"
7474
remotePath := "git::https://github.com/gruntwork-io/terratest.git//examples/terraform-opa-example/policy/enforce_source.rego?ref=v0.50.0"
75+
7576
defer func() {
7677
if cached, ok := opa.PolicyDirCache.Load(baseDir); ok {
7778
downloadPath := cached.(string)
7879
if strings.HasSuffix(downloadPath, "/getter") {
7980
downloadPath = filepath.Dir(downloadPath)
8081
}
82+
8183
os.RemoveAll(downloadPath)
8284
}
8385
}()
@@ -86,25 +88,37 @@ func TestDownloadPolicyDeduplicatesConcurrentDownloads(t *testing.T) {
8688
before, _ := filepath.Glob(tempDirGlob)
8789

8890
const numGoroutines = 5
91+
8992
var wg sync.WaitGroup
93+
9094
results := make([]string, numGoroutines)
95+
errs := make([]error, numGoroutines)
96+
9197
for i := 0; i < numGoroutines; i++ {
9298
wg.Add(1)
99+
93100
go func(idx int) {
94101
defer wg.Done()
102+
95103
path, err := opa.DownloadPolicyE(t, remotePath)
96-
require.NoError(t, err)
104+
105+
errs[idx] = err
97106
results[idx] = path
98107
}(i)
99108
}
109+
100110
wg.Wait()
101111

112+
for i := 0; i < numGoroutines; i++ {
113+
require.NoError(t, errs[i])
114+
}
115+
102116
for i := 1; i < numGoroutines; i++ {
103117
assert.Equal(t, results[0], results[i])
104118
}
105119

106120
after, _ := filepath.Glob(tempDirGlob)
107-
assert.Equal(t, len(before)+1, len(after), "expected exactly one new temp dir; dedup may have failed")
121+
assert.Len(t, after, len(before)+1, "expected exactly one new temp dir; dedup may have failed")
108122
}
109123

110124
// TestDownloadPolicyReusesCachedDir makes sure the DownloadPolicyE function uses the cache if it has already downloaded

0 commit comments

Comments
 (0)