@@ -279,46 +279,74 @@ func TestIdentityIsFullyNull(t *testing.T) {
279
279
inttypes .StringIdentityAttribute ("bucket" , true ),
280
280
}
281
281
282
+ // Create identity schema once for all test cases
283
+ identitySchema := & identityschema.Schema {
284
+ Attributes : map [string ]identityschema.Attribute {
285
+ "account_id" : identityschema.StringAttribute {},
286
+ "region" : identityschema.StringAttribute {},
287
+ "bucket" : identityschema.StringAttribute {},
288
+ },
289
+ }
290
+
291
+ ctx := context .Background ()
292
+
293
+ // Helper function to create identity with values
294
+ createIdentityWithValues := func (values map [string ]string ) * tfsdk.ResourceIdentity {
295
+ if values == nil {
296
+ return nil
297
+ }
298
+ identity := emtpyIdentityFromSchema (ctx , identitySchema )
299
+ for attrName , value := range values {
300
+ if value != "" {
301
+ diags := identity .SetAttribute (ctx , path .Root (attrName ), value )
302
+ if diags .HasError () {
303
+ t .Fatalf ("unexpected error setting %s in identity: %s" , attrName , fwdiag .DiagnosticsError (diags ))
304
+ }
305
+ }
306
+ }
307
+ return identity
308
+ }
309
+
282
310
testCases := map [string ]struct {
283
- identityValues map [ string ] string
284
- expectNull bool
285
- description string
311
+ identity * tfsdk. ResourceIdentity
312
+ expectNull bool
313
+ description string
286
314
}{
287
315
"all_null" : {
288
- identityValues : map [string ]string {},
289
- expectNull : true ,
290
- description : "All attributes null should return true" ,
316
+ identity : createIdentityWithValues ( map [string ]string {}) ,
317
+ expectNull : true ,
318
+ description : "All attributes null should return true" ,
291
319
},
292
320
"some_null" : {
293
- identityValues : map [string ]string {
321
+ identity : createIdentityWithValues ( map [string ]string {
294
322
"account_id" : "123456789012" ,
295
323
// region and bucket remain null
296
- },
324
+ }) ,
297
325
expectNull : false ,
298
326
description : "Some attributes set should return false" ,
299
327
},
300
328
"all_set" : {
301
- identityValues : map [string ]string {
329
+ identity : createIdentityWithValues ( map [string ]string {
302
330
"account_id" : "123456789012" ,
303
331
"region" : "us-west-2" , // lintignore:AWSAT003
304
332
"bucket" : "test-bucket" ,
305
- },
333
+ }) ,
306
334
expectNull : false ,
307
335
description : "All attributes set should return false" ,
308
336
},
309
337
"empty_string_values" : {
310
- identityValues : map [string ]string {
338
+ identity : createIdentityWithValues ( map [string ]string {
311
339
"account_id" : "" ,
312
340
"region" : "" ,
313
341
"bucket" : "" ,
314
- },
342
+ }) ,
315
343
expectNull : true ,
316
344
description : "Empty string values should be treated as null" ,
317
345
},
318
346
"nil_identity" : {
319
- identityValues : nil , // This will result in nil identity
320
- expectNull : true ,
321
- description : "Nil identity should return true" ,
347
+ identity : createIdentityWithValues ( nil ),
348
+ expectNull : true ,
349
+ description : "Nil identity should return true" ,
322
350
},
323
351
}
324
352
@@ -327,34 +355,7 @@ func TestIdentityIsFullyNull(t *testing.T) {
327
355
t .Parallel ()
328
356
ctx := context .Background ()
329
357
330
- // Create identity schema
331
- identitySchema := & identityschema.Schema {
332
- Attributes : map [string ]identityschema.Attribute {
333
- "account_id" : identityschema.StringAttribute {},
334
- "region" : identityschema.StringAttribute {},
335
- "bucket" : identityschema.StringAttribute {},
336
- },
337
- }
338
-
339
- var identity * tfsdk.ResourceIdentity
340
-
341
- // Handle nil identity case
342
- if tc .identityValues == nil {
343
- identity = nil
344
- } else {
345
- // Create identity with values
346
- identity = emtpyIdentityFromSchema (ctx , identitySchema )
347
- for attrName , value := range tc .identityValues {
348
- if value != "" {
349
- diags := identity .SetAttribute (ctx , path .Root (attrName ), value )
350
- if diags .HasError () {
351
- t .Fatalf ("unexpected error setting %s in identity: %s" , attrName , fwdiag .DiagnosticsError (diags ))
352
- }
353
- }
354
- }
355
- }
356
-
357
- result := identityIsFullyNull (ctx , identity , attributes )
358
+ result := identityIsFullyNull (ctx , tc .identity , attributes )
358
359
if result != tc .expectNull {
359
360
t .Errorf ("%s: expected identityIsFullyNull to return %v, got %v" ,
360
361
tc .description , tc .expectNull , result )
0 commit comments