@@ -189,32 +189,37 @@ func TestIdentityInterceptor_Update(t *testing.T) {
189
189
attrName string
190
190
identitySpec inttypes.Identity
191
191
ExpectIdentity bool
192
+ Description string
192
193
}{
193
- "not mutable" : {
194
+ "not mutable - fresh resource " : {
194
195
attrName : "name" ,
195
196
identitySpec : regionalSingleParameterizedIdentitySpec ("name" ),
196
- ExpectIdentity : false ,
197
+ ExpectIdentity : true ,
198
+ Description : "Immutable identity with all null attributes should get populated (bug fix scenario)" ,
197
199
},
198
200
"v6.0 SDK fix" : {
199
201
attrName : "name" ,
200
202
identitySpec : regionalSingleParameterizedIdentitySpec ("name" ,
201
203
inttypes .WithV6_0SDKv2Fix (),
202
204
),
203
- ExpectIdentity : false ,
205
+ ExpectIdentity : true ,
206
+ Description : "Mutable identity (v6.0 SDK fix) should always get populated on Update" ,
204
207
},
205
208
"identity fix" : {
206
209
attrName : "name" ,
207
210
identitySpec : regionalSingleParameterizedIdentitySpec ("name" ,
208
211
inttypes .WithIdentityFix (),
209
212
),
210
- ExpectIdentity : false ,
213
+ ExpectIdentity : true ,
214
+ Description : "Mutable identity (identity fix) should always get populated on Update" ,
211
215
},
212
216
"mutable" : {
213
217
attrName : "name" ,
214
218
identitySpec : regionalSingleParameterizedIdentitySpec ("name" ,
215
219
inttypes .WithMutableIdentity (),
216
220
),
217
221
ExpectIdentity : true ,
222
+ Description : "Explicitly mutable identity should always get populated on Update" ,
218
223
},
219
224
}
220
225
@@ -317,3 +322,82 @@ func (c mockClient) ValidateInContextRegionInPartition(ctx context.Context) erro
317
322
func (c mockClient ) AwsConfig (context.Context ) aws.Config { // nosemgrep:ci.aws-in-func-name
318
323
panic ("not implemented" ) //lintignore:R009
319
324
}
325
+
326
+ func TestIdentityIsFullyNull (t * testing.T ) {
327
+ t .Parallel ()
328
+
329
+ identitySpec := & inttypes.Identity {
330
+ Attributes : []inttypes.IdentityAttribute {
331
+ inttypes .StringIdentityAttribute (names .AttrAccountID , false ),
332
+ inttypes .StringIdentityAttribute (names .AttrRegion , false ),
333
+ inttypes .StringIdentityAttribute (names .AttrBucket , true ),
334
+ },
335
+ }
336
+
337
+ testCases := map [string ]struct {
338
+ identityValues map [string ]string
339
+ expectNull bool
340
+ description string
341
+ }{
342
+ "all_null" : {
343
+ identityValues : map [string ]string {},
344
+ expectNull : true ,
345
+ description : "All attributes null should return true" ,
346
+ },
347
+ "some_null" : {
348
+ identityValues : map [string ]string {
349
+ names .AttrAccountID : "123456789012" ,
350
+ // region and bucket remain null
351
+ },
352
+ expectNull : false ,
353
+ description : "Some attributes set should return false" ,
354
+ },
355
+ "all_set" : {
356
+ identityValues : map [string ]string {
357
+ names .AttrAccountID : "123456789012" ,
358
+ names .AttrRegion : "us-west-2" , // lintignore:AWSAT003
359
+ names .AttrBucket : "test-bucket" ,
360
+ },
361
+ expectNull : false ,
362
+ description : "All attributes set should return false" ,
363
+ },
364
+ "empty_string_values" : {
365
+ identityValues : map [string ]string {
366
+ names .AttrAccountID : "" ,
367
+ names .AttrRegion : "" ,
368
+ names .AttrBucket : "" ,
369
+ },
370
+ expectNull : true ,
371
+ description : "Empty string values should be treated as null" ,
372
+ },
373
+ }
374
+
375
+ for name , tc := range testCases {
376
+ t .Run (name , func (t * testing.T ) {
377
+ t .Parallel ()
378
+
379
+ resourceSchema := map [string ]* schema.Schema {
380
+ names .AttrBucket : {Type : schema .TypeString , Required : true },
381
+ }
382
+ identitySchema := identity .NewIdentitySchema (* identitySpec )
383
+ d := schema .TestResourceDataWithIdentityRaw (t , resourceSchema , identitySchema , nil )
384
+ d .SetId ("test-id" )
385
+
386
+ identity , err := d .Identity ()
387
+ if err != nil {
388
+ t .Fatalf ("unexpected error getting identity: %v" , err )
389
+ }
390
+ for attrName , value := range tc .identityValues {
391
+ if err := identity .Set (attrName , value ); err != nil {
392
+ t .Fatalf ("unexpected error setting %s in identity: %v" , attrName , err )
393
+ }
394
+ }
395
+
396
+ result := identityIsFullyNull (d , identitySpec )
397
+ if result != tc .expectNull {
398
+ t .Errorf ("%s: expected identityIsFullyNull to return %v, got %v" ,
399
+ tc .description , tc .expectNull , result )
400
+ }
401
+ })
402
+ }
403
+ }
0 commit comments