@@ -514,62 +514,64 @@ func TestAccDataSource_basic(t *testing.T) {
514514
515515 // Iterate over the provided configurations for datasources
516516 for _ , test := range resourceTests {
517- // Always check that the resource was created and that `id` is a number
518- checks := []resource.TestCheckFunc {
519- testAccDataSourceCheckExists (test .resource , & dataSource ),
520- resource .TestMatchResourceAttr (
521- test .resource ,
522- "id" ,
523- idRegexp ,
524- ),
525- resource .TestMatchResourceAttr (
526- test .resource ,
527- "uid" ,
528- uidRegexp ,
529- ),
530- }
517+ t .Run (test .resource , func (t * testing.T ) {
518+ // Always check that the resource was created and that `id` is a number
519+ checks := []resource.TestCheckFunc {
520+ testAccDataSourceCheckExists (test .resource , & dataSource ),
521+ resource .TestMatchResourceAttr (
522+ test .resource ,
523+ "id" ,
524+ idRegexp ,
525+ ),
526+ resource .TestMatchResourceAttr (
527+ test .resource ,
528+ "uid" ,
529+ uidRegexp ,
530+ ),
531+ }
531532
532- // Add custom checks for specified attribute values
533- for attr , value := range test .attrChecks {
534- checks = append (checks , resource .TestCheckResourceAttr (
535- test .resource ,
536- attr ,
537- value ,
538- ))
539- }
533+ // Add custom checks for specified attribute values
534+ for attr , value := range test .attrChecks {
535+ checks = append (checks , resource .TestCheckResourceAttr (
536+ test .resource ,
537+ attr ,
538+ value ,
539+ ))
540+ }
540541
541- resource .Test (t , resource.TestCase {
542- ProviderFactories : testAccProviderFactories ,
543- CheckDestroy : testAccDataSourceCheckDestroy (& dataSource ),
544- Steps : []resource.TestStep {
545- {
546- Config : test .config ,
547- Check : resource .ComposeAggregateTestCheckFunc (
548- append (checks , test .additionalChecks ... )... ,
549- ),
550- },
551- // Test import using ID
552- {
553- ResourceName : test .resource ,
554- ImportState : true ,
555- },
556- // Test import using UID
557- {
558- ResourceName : test .resource ,
559- ImportState : true ,
560- ImportStateIdFunc : func (s * terraform.State ) (string , error ) {
561- rs , ok := s .RootModule ().Resources [test .resource ]
562- if ! ok {
563- return "" , fmt .Errorf ("resource not found: %s" , test .resource )
564- }
542+ resource .Test (t , resource.TestCase {
543+ ProviderFactories : testAccProviderFactories ,
544+ CheckDestroy : testAccDataSourceCheckDestroy (& dataSource ),
545+ Steps : []resource.TestStep {
546+ {
547+ Config : test .config ,
548+ Check : resource .ComposeAggregateTestCheckFunc (
549+ append (checks , test .additionalChecks ... )... ,
550+ ),
551+ },
552+ // Test import using ID
553+ {
554+ ResourceName : test .resource ,
555+ ImportState : true ,
556+ },
557+ // Test import using UID
558+ {
559+ ResourceName : test .resource ,
560+ ImportState : true ,
561+ ImportStateIdFunc : func (s * terraform.State ) (string , error ) {
562+ rs , ok := s .RootModule ().Resources [test .resource ]
563+ if ! ok {
564+ return "" , fmt .Errorf ("resource not found: %s" , test .resource )
565+ }
565566
566- if rs .Primary .ID == "" {
567- return "" , fmt .Errorf ("resource id not set" )
568- }
569- return rs .Primary .Attributes ["uid" ], nil
567+ if rs .Primary .ID == "" {
568+ return "" , fmt .Errorf ("resource id not set" )
569+ }
570+ return rs .Primary .Attributes ["uid" ], nil
571+ },
570572 },
571573 },
572- },
574+ })
573575 })
574576 }
575577}
0 commit comments