Skip to content

Commit 0b591e1

Browse files
committed
test(ibmsm): Look for data races
1 parent f0d0df7 commit 0b591e1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ default: build
44

55
quality:
66
go vet github.com/argoproj-labs/argocd-vault-plugin
7-
go test -v -coverprofile cover.out ./...
7+
go test -race -v -coverprofile cover.out ./...
88

99
build:
1010
go build -o ${BINARY} .

Diff for: pkg/backends/ibmsecretsmanager_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"reflect"
66
"strings"
77
"testing"
8+
"sync"
89

910
"github.com/IBM/go-sdk-core/v5/core"
1011
ibmsm "github.com/IBM/secrets-manager-go-sdk/secretsmanagerv2"
@@ -14,6 +15,11 @@ import (
1415

1516
type MockIBMSMClient struct {
1617
ListSecretsOptionCalledWith []*ibmsm.ListSecretsOptions
18+
19+
// GetSecretLock prevents false data races caused by unsychronized access to the mock state
20+
// It is shared b/w both GetSecret and GetSecretVersion for simplicity, even though each writes to a different field
21+
GetSecretLock sync.RWMutex
22+
1723
GetSecretCalledWith *ibmsm.GetSecretOptions
1824
GetSecretCallCount int
1925
GetSecretVersionCalledWith *ibmsm.GetSecretVersionOptions
@@ -112,8 +118,10 @@ func (m *MockIBMSMClient) ListSecrets(listAllSecretsOptions *ibmsm.ListSecretsOp
112118
}
113119

114120
func (m *MockIBMSMClient) GetSecret(getSecretOptions *ibmsm.GetSecretOptions) (result ibmsm.SecretIntf, response *core.DetailedResponse, err error) {
121+
m.GetSecretLock.Lock()
115122
m.GetSecretCalledWith = getSecretOptions
116123
m.GetSecretCallCount += 1
124+
m.GetSecretLock.Unlock()
117125

118126
if *getSecretOptions.ID == "arbitrary" {
119127
name := "my-secret"
@@ -148,8 +156,10 @@ func (m *MockIBMSMClient) GetSecret(getSecretOptions *ibmsm.GetSecretOptions) (r
148156
}
149157

150158
func (m *MockIBMSMClient) GetSecretVersion(getSecretOptions *ibmsm.GetSecretVersionOptions) (result ibmsm.SecretVersionIntf, response *core.DetailedResponse, err error) {
159+
m.GetSecretLock.Lock()
151160
m.GetSecretVersionCalledWith = getSecretOptions
152161
m.GetSecretVersionCallCount += 1
162+
m.GetSecretLock.Unlock()
153163
data := "dummy"
154164
id := "public_cert"
155165
yes := true

0 commit comments

Comments
 (0)