Skip to content

Commit

Permalink
test(ibmsm): Look for data races
Browse files Browse the repository at this point in the history
  • Loading branch information
jkayani authored and werne2j committed Jun 18, 2023
1 parent 390a13b commit dbaf2d0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 1 addition & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
# golang:1.17-alpine
FROM golang@sha256:f4ece20984a30d1065b04653bf6781f51ab63421b4b8f011565de0401cfe58d7

RUN apk add make git
FROM index.docker.io/golang:1.17@sha256:55636cf1983628109e569690596b85077f45aca810a77904e8afad48b49aa500

ADD go.mod go.mod
ADD go.sum go.sum

ENV GOPATH=""
ENV CGO_ENABLED=0
RUN go mod download

VOLUME work
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default: build

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

build:
go build -o ${BINARY} .
Expand Down
10 changes: 10 additions & 0 deletions pkg/backends/ibmsecretsmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"reflect"
"strings"
"testing"
"sync"

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

type MockIBMSMClient struct {
ListSecretsOptionCalledWith []*ibmsm.ListSecretsOptions

// GetSecretLock prevents false data races caused by unsychronized access to the mock state
// It is shared b/w both GetSecret and GetSecretVersion for simplicity, even though each writes to a different field
GetSecretLock sync.RWMutex

GetSecretCalledWith *ibmsm.GetSecretOptions
GetSecretCallCount int
GetSecretVersionCalledWith *ibmsm.GetSecretVersionOptions
Expand Down Expand Up @@ -112,8 +118,10 @@ func (m *MockIBMSMClient) ListSecrets(listAllSecretsOptions *ibmsm.ListSecretsOp
}

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

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

func (m *MockIBMSMClient) GetSecretVersion(getSecretOptions *ibmsm.GetSecretVersionOptions) (result ibmsm.SecretVersionIntf, response *core.DetailedResponse, err error) {
m.GetSecretLock.Lock()
m.GetSecretVersionCalledWith = getSecretOptions
m.GetSecretVersionCallCount += 1
m.GetSecretLock.Unlock()
data := "dummy"
id := "public_cert"
yes := true
Expand Down

0 comments on commit dbaf2d0

Please sign in to comment.