From d70e2453c83c8e4f1fd16387229ed2dfc5211963 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Mon, 5 Apr 2021 08:12:01 -0400 Subject: [PATCH] tests/provider: Fix and enable tfproviderlint AT012 for mismatched acceptance test prefixes within a single file (#18526) Reference: https://github.com/hashicorp/terraform-provider-aws/issues/18377 This selection process was just choosing the most prominent naming convention within the files, not making any assertions about which is better. The ELB "Update" tests were just configuration update versions of the non-"Update" tests so consolidated to just the updating tests. The EB import test was the same as the basic test so moved the import step to the basic test as is customary. Output from acceptance testing for modified tests: ``` --- PASS: TestAccAWSBeanstalkApp_basic (17.01s) ``` --- GNUmakefile | 1 - ...ce_aws_directory_service_directory_test.go | 2 +- ...ta_source_aws_launch_configuration_test.go | 2 +- aws/data_source_aws_lb_target_group_test.go | 2 +- aws/provider_test.go | 2 +- aws/resource_aws_db_option_group_test.go | 2 +- ..._aws_elastic_beanstalk_application_test.go | 40 ++------ aws/resource_aws_elb_test.go | 97 ------------------- aws/resource_aws_opsworks_stack_test.go | 2 +- aws/resource_aws_s3_bucket_test.go | 2 +- 10 files changed, 14 insertions(+), 138 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 2970b2890cf..fb365a02a5e 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -94,7 +94,6 @@ awsproviderlint: -AWSAT006=false \ -AWSV001=false \ -AT010=false \ - -AT012=false \ -R001=false \ -R010=false \ -R018=false \ diff --git a/aws/data_source_aws_directory_service_directory_test.go b/aws/data_source_aws_directory_service_directory_test.go index f6742d3bc07..b0eb26bbac4 100644 --- a/aws/data_source_aws_directory_service_directory_test.go +++ b/aws/data_source_aws_directory_service_directory_test.go @@ -89,7 +89,7 @@ func TestAccDataSourceAwsDirectoryServiceDirectory_MicrosoftAD(t *testing.T) { }) } -func TestAccDataSourceAWSDirectoryServiceDirectory_connector(t *testing.T) { +func TestAccDataSourceAwsDirectoryServiceDirectory_connector(t *testing.T) { resourceName := "aws_directory_service_directory.connector" dataSourceName := "data.aws_directory_service_directory.test-ad-connector" diff --git a/aws/data_source_aws_launch_configuration_test.go b/aws/data_source_aws_launch_configuration_test.go index e482d551d08..b4c2efb6af8 100644 --- a/aws/data_source_aws_launch_configuration_test.go +++ b/aws/data_source_aws_launch_configuration_test.go @@ -81,7 +81,7 @@ func TestAccAWSLaunchConfigurationDataSource_ebsNoDevice(t *testing.T) { }) } -func TestAccLaunchConfigurationDataSource_metadataOptions(t *testing.T) { +func TestAccAWSLaunchConfigurationDataSource_metadataOptions(t *testing.T) { rName := acctest.RandomWithPrefix("tf-acc-test") dataSourceName := "data.aws_launch_configuration.test" resourceName := "aws_launch_configuration.test" diff --git a/aws/data_source_aws_lb_target_group_test.go b/aws/data_source_aws_lb_target_group_test.go index 6c6abbf8976..09300bb7c23 100644 --- a/aws/data_source_aws_lb_target_group_test.go +++ b/aws/data_source_aws_lb_target_group_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) -func TestAccDataSourceAWSALBTargetGroup_basic(t *testing.T) { +func TestAccDataSourceAWSLBTargetGroup_basic(t *testing.T) { rName := acctest.RandomWithPrefix("tf-acc-test") resourceNameArn := "data.aws_lb_target_group.alb_tg_test_with_arn" resourceName := "data.aws_lb_target_group.alb_tg_test_with_name" diff --git a/aws/provider_test.go b/aws/provider_test.go index a56c39f70dc..1a27e8c2382 100644 --- a/aws/provider_test.go +++ b/aws/provider_test.go @@ -1181,7 +1181,7 @@ func testAccPreCheckSkipError(err error) bool { return false } -func TestAccProvider_DefaultTags_EmptyConfigurationBlock(t *testing.T) { +func TestAccAWSProvider_DefaultTags_EmptyConfigurationBlock(t *testing.T) { var providers []*schema.Provider resource.ParallelTest(t, resource.TestCase{ diff --git a/aws/resource_aws_db_option_group_test.go b/aws/resource_aws_db_option_group_test.go index c5c8f431960..19b7d370e3e 100644 --- a/aws/resource_aws_db_option_group_test.go +++ b/aws/resource_aws_db_option_group_test.go @@ -184,7 +184,7 @@ func TestAccAWSDBOptionGroup_generatedName(t *testing.T) { }) } -func TestAccAWSDBOptionGroupConfig_OptionGroupDescription(t *testing.T) { +func TestAccAWSDBOptionGroup_OptionGroupDescription(t *testing.T) { var optionGroup1 rds.OptionGroup rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_db_option_group.test" diff --git a/aws/resource_aws_elastic_beanstalk_application_test.go b/aws/resource_aws_elastic_beanstalk_application_test.go index 897c672c39e..a9bd4597f4a 100644 --- a/aws/resource_aws_elastic_beanstalk_application_test.go +++ b/aws/resource_aws_elastic_beanstalk_application_test.go @@ -62,41 +62,10 @@ func testSweepElasticBeanstalkApplications(region string) error { return errors } -func TestAccAWSElasticBeanstalkApplication_basic(t *testing.T) { - resourceName := "aws_elastic_beanstalk_application.tftest" - config := fmt.Sprintf("tf-test-name-%d", acctest.RandInt()) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, elasticbeanstalk.EndpointsID), - Providers: testAccProviders, - CheckDestroy: testAccCheckBeanstalkAppDestroy, - Steps: []resource.TestStep{ - { - Config: testAccBeanstalkAppImportConfig(config), - }, - - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccBeanstalkAppImportConfig(name string) string { - return fmt.Sprintf(` -resource "aws_elastic_beanstalk_application" "tftest" { - name = "%s" - description = "tf-test-desc" -} -`, name) -} - func TestAccAWSBeanstalkApp_basic(t *testing.T) { var app elasticbeanstalk.ApplicationDescription rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_elastic_beanstalk_application.tftest" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -107,9 +76,14 @@ func TestAccAWSBeanstalkApp_basic(t *testing.T) { { Config: testAccBeanstalkAppConfig(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckBeanstalkAppExists("aws_elastic_beanstalk_application.tftest", &app), + testAccCheckBeanstalkAppExists(resourceName, &app), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, }, }) } diff --git a/aws/resource_aws_elb_test.go b/aws/resource_aws_elb_test.go index 94dfd9c0e73..140d037ad21 100644 --- a/aws/resource_aws_elb_test.go +++ b/aws/resource_aws_elb_test.go @@ -614,33 +614,6 @@ func TestAccAWSELB_listener(t *testing.T) { } func TestAccAWSELB_HealthCheck(t *testing.T) { - var conf elb.LoadBalancerDescription - resourceName := "aws_elb.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, elb.EndpointsID), - IDRefreshName: resourceName, - Providers: testAccProviders, - CheckDestroy: testAccCheckAWSELBDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSELBConfigHealthCheck, - Check: resource.ComposeTestCheckFunc( - testAccCheckAWSELBExists(resourceName, &conf), - testAccCheckAWSELBAttributesHealthCheck(&conf), - resource.TestCheckResourceAttr(resourceName, "health_check.0.healthy_threshold", "5"), - resource.TestCheckResourceAttr(resourceName, "health_check.0.unhealthy_threshold", "5"), - resource.TestCheckResourceAttr(resourceName, "health_check.0.target", "HTTP:8000/"), - resource.TestCheckResourceAttr(resourceName, "health_check.0.timeout", "30"), - resource.TestCheckResourceAttr(resourceName, "health_check.0.interval", "60"), - ), - }, - }, - }) -} - -func TestAccAWSELBUpdate_HealthCheck(t *testing.T) { resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ @@ -668,28 +641,6 @@ func TestAccAWSELBUpdate_HealthCheck(t *testing.T) { } func TestAccAWSELB_Timeout(t *testing.T) { - var conf elb.LoadBalancerDescription - resourceName := "aws_elb.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, elb.EndpointsID), - IDRefreshName: resourceName, - Providers: testAccProviders, - CheckDestroy: testAccCheckAWSELBDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSELBConfigIdleTimeout, - Check: resource.ComposeTestCheckFunc( - testAccCheckAWSELBExists(resourceName, &conf), - resource.TestCheckResourceAttr(resourceName, "idle_timeout", "200"), - ), - }, - }, - }) -} - -func TestAccAWSELBUpdate_Timeout(t *testing.T) { resourceName := "aws_elb.test" resource.ParallelTest(t, resource.TestCase{ @@ -718,29 +669,6 @@ func TestAccAWSELBUpdate_Timeout(t *testing.T) { func TestAccAWSELB_ConnectionDraining(t *testing.T) { resourceName := "aws_elb.test" - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, elb.EndpointsID), - IDRefreshName: resourceName, - Providers: testAccProviders, - CheckDestroy: testAccCheckAWSELBDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSELBConfigConnectionDraining, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - resourceName, "connection_draining", "true", - ), - resource.TestCheckResourceAttr(resourceName, "connection_draining_timeout", "400"), - ), - }, - }, - }) -} - -func TestAccAWSELBUpdate_ConnectionDraining(t *testing.T) { - resourceName := "aws_elb.test" - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ErrorCheck: testAccErrorCheck(t, elb.EndpointsID), @@ -1075,31 +1003,6 @@ func testAccCheckAWSELBAttributes(conf *elb.LoadBalancerDescription) resource.Te } } -func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancerDescription) resource.TestCheckFunc { - return func(s *terraform.State) error { - check := &elb.HealthCheck{ - Timeout: aws.Int64(int64(30)), - UnhealthyThreshold: aws.Int64(int64(5)), - HealthyThreshold: aws.Int64(int64(5)), - Interval: aws.Int64(int64(60)), - Target: aws.String("HTTP:8000/"), - } - - if !reflect.DeepEqual(conf.HealthCheck, check) { - return fmt.Errorf( - "Got:\n\n%#v\n\nExpected:\n\n%#v\n", - conf.HealthCheck, - check) - } - - if *conf.DNSName == "" { - return fmt.Errorf("empty dns_name") - } - - return nil - } -} - func testAccCheckAWSELBExists(n string, res *elb.LoadBalancerDescription) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] diff --git a/aws/resource_aws_opsworks_stack_test.go b/aws/resource_aws_opsworks_stack_test.go index a35106ef2ad..b91f5758070 100644 --- a/aws/resource_aws_opsworks_stack_test.go +++ b/aws/resource_aws_opsworks_stack_test.go @@ -219,7 +219,7 @@ func TestAccAWSOpsworksStack_CustomCookbooks_SetPrivateProperties(t *testing.T) // Tests the addition of regional endpoints and supporting the classic link used // to create Stack's prior to v0.9.0. // See https://github.com/hashicorp/terraform/issues/12842 -func TestAccAWSOpsWorksStack_classicEndpoints(t *testing.T) { +func TestAccAWSOpsworksStack_classicEndpoints(t *testing.T) { stackName := fmt.Sprintf("tf-opsworks-acc-%d", acctest.RandInt()) resourceName := "aws_opsworks_stack.main" rInt := acctest.RandInt() diff --git a/aws/resource_aws_s3_bucket_test.go b/aws/resource_aws_s3_bucket_test.go index a3ab7e44f0e..a7e1a196f38 100644 --- a/aws/resource_aws_s3_bucket_test.go +++ b/aws/resource_aws_s3_bucket_test.go @@ -416,7 +416,7 @@ func TestAccAWSS3Bucket_ignoreTags(t *testing.T) { }) } -func TestAccAWSS3MultiBucket_withTags(t *testing.T) { +func TestAccAWSS3Bucket_withTags(t *testing.T) { rInt := acctest.RandInt() resourceName := "aws_s3_bucket.bucket1"