5
5
"reflect"
6
6
"strings"
7
7
"testing"
8
+ "sync"
8
9
9
10
"github.com/IBM/go-sdk-core/v5/core"
10
11
ibmsm "github.com/IBM/secrets-manager-go-sdk/secretsmanagerv2"
@@ -14,6 +15,11 @@ import (
14
15
15
16
type MockIBMSMClient struct {
16
17
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
+
17
23
GetSecretCalledWith * ibmsm.GetSecretOptions
18
24
GetSecretCallCount int
19
25
GetSecretVersionCalledWith * ibmsm.GetSecretVersionOptions
@@ -112,8 +118,10 @@ func (m *MockIBMSMClient) ListSecrets(listAllSecretsOptions *ibmsm.ListSecretsOp
112
118
}
113
119
114
120
func (m * MockIBMSMClient ) GetSecret (getSecretOptions * ibmsm.GetSecretOptions ) (result ibmsm.SecretIntf , response * core.DetailedResponse , err error ) {
121
+ m .GetSecretLock .Lock ()
115
122
m .GetSecretCalledWith = getSecretOptions
116
123
m .GetSecretCallCount += 1
124
+ m .GetSecretLock .Unlock ()
117
125
118
126
if * getSecretOptions .ID == "arbitrary" {
119
127
name := "my-secret"
@@ -148,8 +156,10 @@ func (m *MockIBMSMClient) GetSecret(getSecretOptions *ibmsm.GetSecretOptions) (r
148
156
}
149
157
150
158
func (m * MockIBMSMClient ) GetSecretVersion (getSecretOptions * ibmsm.GetSecretVersionOptions ) (result ibmsm.SecretVersionIntf , response * core.DetailedResponse , err error ) {
159
+ m .GetSecretLock .Lock ()
151
160
m .GetSecretVersionCalledWith = getSecretOptions
152
161
m .GetSecretVersionCallCount += 1
162
+ m .GetSecretLock .Unlock ()
153
163
data := "dummy"
154
164
id := "public_cert"
155
165
yes := true
0 commit comments