@@ -189,32 +189,37 @@ func TestIdentityInterceptor_Update(t *testing.T) {
189189 attrName string
190190 identitySpec inttypes.Identity
191191 ExpectIdentity bool
192+ Description string
192193 }{
193- "not mutable" : {
194+ "not mutable - fresh resource " : {
194195 attrName : "name" ,
195196 identitySpec : regionalSingleParameterizedIdentitySpec ("name" ),
196- ExpectIdentity : false ,
197+ ExpectIdentity : true ,
198+ Description : "Immutable identity with all null attributes should get populated (bug fix scenario)" ,
197199 },
198200 "v6.0 SDK fix" : {
199201 attrName : "name" ,
200202 identitySpec : regionalSingleParameterizedIdentitySpec ("name" ,
201203 inttypes .WithV6_0SDKv2Fix (),
202204 ),
203- ExpectIdentity : false ,
205+ ExpectIdentity : true ,
206+ Description : "Mutable identity (v6.0 SDK fix) should always get populated on Update" ,
204207 },
205208 "identity fix" : {
206209 attrName : "name" ,
207210 identitySpec : regionalSingleParameterizedIdentitySpec ("name" ,
208211 inttypes .WithIdentityFix (),
209212 ),
210- ExpectIdentity : false ,
213+ ExpectIdentity : true ,
214+ Description : "Mutable identity (identity fix) should always get populated on Update" ,
211215 },
212216 "mutable" : {
213217 attrName : "name" ,
214218 identitySpec : regionalSingleParameterizedIdentitySpec ("name" ,
215219 inttypes .WithMutableIdentity (),
216220 ),
217221 ExpectIdentity : true ,
222+ Description : "Explicitly mutable identity should always get populated on Update" ,
218223 },
219224 }
220225
@@ -317,3 +322,82 @@ func (c mockClient) ValidateInContextRegionInPartition(ctx context.Context) erro
317322func (c mockClient ) AwsConfig (context.Context ) aws.Config { // nosemgrep:ci.aws-in-func-name
318323 panic ("not implemented" ) //lintignore:R009
319324}
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