3131 testInstanceId = uuid .NewString ()
3232)
3333
34+ const (
35+ testKmsKeyId = "key-id"
36+ testKmsKeyringId = "keyring-id"
37+ testKmsKeyVersion = int64 (1 )
38+ testKmsServiceAccountEmail = "my-service-account-1234567@sa.stackit.cloud"
39+ )
40+
3441func fixtureArgValues (mods ... func (argValues []string )) []string {
3542 argValues := []string {
3643 testInstanceId ,
@@ -80,6 +87,23 @@ func fixtureRequest(mods ...func(request *secretsmanager.ApiUpdateACLsRequest))
8087 return request
8188}
8289
90+ func fixtureUpdateInstanceRequest (mods ... func (request * secretsmanager.ApiUpdateInstanceRequest )) secretsmanager.ApiUpdateInstanceRequest {
91+ request := testClient .UpdateInstance (testCtx , testProjectId , testInstanceId )
92+ request = request .UpdateInstancePayload (secretsmanager.UpdateInstancePayload {
93+ KmsKey : & secretsmanager.KmsKeyPayload {
94+ KeyId : utils .Ptr (testKmsKeyId ),
95+ KeyRingId : utils .Ptr (testKmsKeyringId ),
96+ KeyVersion : utils .Ptr (testKmsKeyVersion ),
97+ ServiceAccountEmail : utils .Ptr (testKmsServiceAccountEmail ),
98+ },
99+ })
100+
101+ for _ , mod := range mods {
102+ mod (& request )
103+ }
104+ return request
105+ }
106+
83107func TestParseInput (t * testing.T ) {
84108 tests := []struct {
85109 description string
@@ -209,6 +233,25 @@ func TestParseInput(t *testing.T) {
209233 )
210234 }),
211235 },
236+ {
237+ description : "kms flags" ,
238+ argValues : fixtureArgValues (),
239+ flagValues : map [string ]string {
240+ projectIdFlag : testProjectId ,
241+ kmsKeyIdFlag : testKmsKeyId ,
242+ kmsKeyringIdFlag : testKmsKeyringId ,
243+ kmsKeyVersionFlag : "1" ,
244+ kmsServiceAccountEmailFlag : testKmsServiceAccountEmail ,
245+ },
246+ isValid : true ,
247+ expectedModel : fixtureInputModel (func (model * inputModel ) {
248+ model .Acls = nil
249+ model .KmsKeyId = utils .Ptr (testKmsKeyId )
250+ model .KmsKeyringId = utils .Ptr (testKmsKeyringId )
251+ model .KmsKeyVersion = utils .Ptr (testKmsKeyVersion )
252+ model .KmsServiceAccountEmail = utils .Ptr (testKmsServiceAccountEmail )
253+ }),
254+ },
212255 }
213256
214257 for _ , tt := range tests {
@@ -246,8 +289,12 @@ func TestBuildRequest(t *testing.T) {
246289 for _ , tt := range tests {
247290 t .Run (tt .description , func (t * testing.T ) {
248291 request := buildRequest (testCtx , tt .model , testClient )
292+ aclRequest , ok := request .(secretsmanager.ApiUpdateACLsRequest )
293+ if ! ok {
294+ t .Fatalf ("expected ACL update request, got %T" , request )
295+ }
249296
250- diff := cmp .Diff (request , tt .expectedRequest ,
297+ diff := cmp .Diff (aclRequest , tt .expectedRequest ,
251298 cmp .AllowUnexported (tt .expectedRequest ),
252299 cmpopts .EquateComparable (testCtx ),
253300 )
@@ -257,3 +304,28 @@ func TestBuildRequest(t *testing.T) {
257304 })
258305 }
259306}
307+
308+ func TestBuildRequestKms (t * testing.T ) {
309+ model := fixtureInputModel (func (model * inputModel ) {
310+ model .Acls = nil
311+ model .KmsKeyId = utils .Ptr (testKmsKeyId )
312+ model .KmsKeyringId = utils .Ptr (testKmsKeyringId )
313+ model .KmsKeyVersion = utils .Ptr (testKmsKeyVersion )
314+ model .KmsServiceAccountEmail = utils .Ptr (testKmsServiceAccountEmail )
315+ })
316+
317+ request := buildRequest (testCtx , model , testClient )
318+ updateRequest , ok := request .(secretsmanager.ApiUpdateInstanceRequest )
319+ if ! ok {
320+ t .Fatalf ("expected instance update request, got %T" , request )
321+ }
322+
323+ expectedRequest := fixtureUpdateInstanceRequest ()
324+ diff := cmp .Diff (updateRequest , expectedRequest ,
325+ cmp .AllowUnexported (expectedRequest ),
326+ cmpopts .EquateComparable (testCtx ),
327+ )
328+ if diff != "" {
329+ t .Fatalf ("Data does not match: %s" , diff )
330+ }
331+ }
0 commit comments