From 85759cceb78d60236fa14ee715af598aa23dee52 Mon Sep 17 00:00:00 2001 From: Ryn Daniels Date: Mon, 2 Sep 2019 17:48:19 +0200 Subject: [PATCH] Acceptance test import refactor for service resources --- ...urce_aws_service_discovery_service_test.go | 88 +++++++++---------- ...ource_aws_servicecatalog_portfolio_test.go | 84 ++++++++---------- 2 files changed, 79 insertions(+), 93 deletions(-) diff --git a/aws/resource_aws_service_discovery_service_test.go b/aws/resource_aws_service_discovery_service_test.go index 79518823a94..896d3173cea 100644 --- a/aws/resource_aws_service_discovery_service_test.go +++ b/aws/resource_aws_service_discovery_service_test.go @@ -12,7 +12,9 @@ import ( ) func TestAccAWSServiceDiscoveryService_private(t *testing.T) { + resourceName := "aws_service_discovery_service.test" rName := acctest.RandString(5) + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSServiceDiscovery(t) }, Providers: testAccProviders, @@ -21,25 +23,30 @@ func TestAccAWSServiceDiscoveryService_private(t *testing.T) { { Config: testAccServiceDiscoveryServiceConfig_private(rName, 5), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsServiceDiscoveryServiceExists("aws_service_discovery_service.test"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "health_check_custom_config.0.failure_threshold", "5"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.dns_records.#", "1"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.dns_records.0.type", "A"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.dns_records.0.ttl", "5"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.routing_policy", "MULTIVALUE"), - resource.TestCheckResourceAttrSet("aws_service_discovery_service.test", "arn"), + testAccCheckAwsServiceDiscoveryServiceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "health_check_custom_config.0.failure_threshold", "5"), + resource.TestCheckResourceAttr(resourceName, "dns_config.0.dns_records.#", "1"), + resource.TestCheckResourceAttr(resourceName, "dns_config.0.dns_records.0.type", "A"), + resource.TestCheckResourceAttr(resourceName, "dns_config.0.dns_records.0.ttl", "5"), + resource.TestCheckResourceAttr(resourceName, "dns_config.0.routing_policy", "MULTIVALUE"), + resource.TestCheckResourceAttrSet(resourceName, "arn"), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, { Config: testAccServiceDiscoveryServiceConfig_private_update(rName, 5), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsServiceDiscoveryServiceExists("aws_service_discovery_service.test"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.dns_records.#", "2"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.dns_records.0.type", "A"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.dns_records.0.ttl", "10"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.dns_records.1.type", "AAAA"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.dns_records.1.ttl", "5"), - resource.TestCheckResourceAttrSet("aws_service_discovery_service.test", "arn"), + testAccCheckAwsServiceDiscoveryServiceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "dns_config.0.dns_records.#", "2"), + resource.TestCheckResourceAttr(resourceName, "dns_config.0.dns_records.0.type", "A"), + resource.TestCheckResourceAttr(resourceName, "dns_config.0.dns_records.0.ttl", "10"), + resource.TestCheckResourceAttr(resourceName, "dns_config.0.dns_records.1.type", "AAAA"), + resource.TestCheckResourceAttr(resourceName, "dns_config.0.dns_records.1.ttl", "5"), + resource.TestCheckResourceAttrSet(resourceName, "arn"), ), }, }, @@ -48,6 +55,8 @@ func TestAccAWSServiceDiscoveryService_private(t *testing.T) { func TestAccAWSServiceDiscoveryService_public(t *testing.T) { rName := acctest.RandString(5) + resourceName := "aws_service_discovery_service.test" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSServiceDiscovery(t) }, Providers: testAccProviders, @@ -56,22 +65,27 @@ func TestAccAWSServiceDiscoveryService_public(t *testing.T) { { Config: testAccServiceDiscoveryServiceConfig_public(rName, 5, "/path"), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsServiceDiscoveryServiceExists("aws_service_discovery_service.test"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "health_check_config.0.type", "HTTP"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "health_check_config.0.failure_threshold", "5"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "health_check_config.0.resource_path", "/path"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.routing_policy", "WEIGHTED"), - resource.TestCheckResourceAttrSet("aws_service_discovery_service.test", "arn"), + testAccCheckAwsServiceDiscoveryServiceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "health_check_config.0.type", "HTTP"), + resource.TestCheckResourceAttr(resourceName, "health_check_config.0.failure_threshold", "5"), + resource.TestCheckResourceAttr(resourceName, "health_check_config.0.resource_path", "/path"), + resource.TestCheckResourceAttr(resourceName, "dns_config.0.routing_policy", "WEIGHTED"), + resource.TestCheckResourceAttrSet(resourceName, "arn"), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, { Config: testAccServiceDiscoveryServiceConfig_public(rName, 3, "/updated-path"), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsServiceDiscoveryServiceExists("aws_service_discovery_service.test"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "health_check_config.0.type", "HTTP"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "health_check_config.0.failure_threshold", "3"), - resource.TestCheckResourceAttr("aws_service_discovery_service.test", "health_check_config.0.resource_path", "/updated-path"), - resource.TestCheckResourceAttrSet("aws_service_discovery_service.test", "arn"), + testAccCheckAwsServiceDiscoveryServiceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "health_check_config.0.type", "HTTP"), + resource.TestCheckResourceAttr(resourceName, "health_check_config.0.failure_threshold", "3"), + resource.TestCheckResourceAttr(resourceName, "health_check_config.0.resource_path", "/updated-path"), + resource.TestCheckResourceAttrSet(resourceName, "arn"), ), }, }, @@ -80,6 +94,8 @@ func TestAccAWSServiceDiscoveryService_public(t *testing.T) { func TestAccAWSServiceDiscoveryService_http(t *testing.T) { rName := acctest.RandString(5) + resourceName := "aws_service_discovery_service.test" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -88,27 +104,11 @@ func TestAccAWSServiceDiscoveryService_http(t *testing.T) { { Config: testAccServiceDiscoveryServiceConfig_http(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsServiceDiscoveryServiceExists("aws_service_discovery_service.test"), - resource.TestCheckResourceAttrSet("aws_service_discovery_service.test", "namespace_id"), - resource.TestCheckResourceAttrSet("aws_service_discovery_service.test", "arn"), + testAccCheckAwsServiceDiscoveryServiceExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "namespace_id"), + resource.TestCheckResourceAttrSet(resourceName, "arn"), ), }, - }, - }) -} - -func TestAccAWSServiceDiscoveryService_import(t *testing.T) { - resourceName := "aws_service_discovery_service.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSServiceDiscovery(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAwsServiceDiscoveryServiceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccServiceDiscoveryServiceConfig_private(acctest.RandString(5), 5), - }, - { ResourceName: resourceName, ImportState: true, diff --git a/aws/resource_aws_servicecatalog_portfolio_test.go b/aws/resource_aws_servicecatalog_portfolio_test.go index 640e2befe96..d4d1bcbc4b9 100644 --- a/aws/resource_aws_servicecatalog_portfolio_test.go +++ b/aws/resource_aws_servicecatalog_portfolio_test.go @@ -14,8 +14,10 @@ import ( ) func TestAccAWSServiceCatalogPortfolio_Basic(t *testing.T) { + resourceName := "aws_servicecatalog_portfolio.test" name := acctest.RandString(5) var dpo servicecatalog.DescribePortfolioOutput + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -24,41 +26,46 @@ func TestAccAWSServiceCatalogPortfolio_Basic(t *testing.T) { { Config: testAccCheckAwsServiceCatalogPortfolioResourceConfigBasic1(name), Check: resource.ComposeTestCheckFunc( - testAccCheckPortfolio("aws_servicecatalog_portfolio.test", &dpo), - resource.TestCheckResourceAttrSet("aws_servicecatalog_portfolio.test", "arn"), - resource.TestCheckResourceAttrSet("aws_servicecatalog_portfolio.test", "created_time"), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "name", name), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "description", "test-2"), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "provider_name", "test-3"), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "tags.%", "1"), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "tags.Key1", "Value One"), + testAccCheckPortfolio(resourceName, &dpo), + resource.TestCheckResourceAttrSet(resourceName, "arn"), + resource.TestCheckResourceAttrSet(resourceName, "created_time"), + resource.TestCheckResourceAttr(resourceName, "name", name), + resource.TestCheckResourceAttr(resourceName, "description", "test-2"), + resource.TestCheckResourceAttr(resourceName, "provider_name", "test-3"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.Key1", "Value One"), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, { Config: testAccCheckAwsServiceCatalogPortfolioResourceConfigBasic2(name), Check: resource.ComposeTestCheckFunc( - testAccCheckPortfolio("aws_servicecatalog_portfolio.test", &dpo), - resource.TestCheckResourceAttrSet("aws_servicecatalog_portfolio.test", "arn"), - resource.TestCheckResourceAttrSet("aws_servicecatalog_portfolio.test", "created_time"), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "name", name), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "description", "test-b"), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "provider_name", "test-c"), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "tags.%", "2"), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "tags.Key1", "Value 1"), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "tags.Key2", "Value Two"), + testAccCheckPortfolio(resourceName, &dpo), + resource.TestCheckResourceAttrSet(resourceName, "arn"), + resource.TestCheckResourceAttrSet(resourceName, "created_time"), + resource.TestCheckResourceAttr(resourceName, "name", name), + resource.TestCheckResourceAttr(resourceName, "description", "test-b"), + resource.TestCheckResourceAttr(resourceName, "provider_name", "test-c"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.Key1", "Value 1"), + resource.TestCheckResourceAttr(resourceName, "tags.Key2", "Value Two"), ), }, { Config: testAccCheckAwsServiceCatalogPortfolioResourceConfigBasic3(name), Check: resource.ComposeTestCheckFunc( - testAccCheckPortfolio("aws_servicecatalog_portfolio.test", &dpo), - resource.TestCheckResourceAttrSet("aws_servicecatalog_portfolio.test", "arn"), - resource.TestCheckResourceAttrSet("aws_servicecatalog_portfolio.test", "created_time"), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "name", name), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "description", "test-only-change-me"), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "provider_name", "test-c"), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "tags.%", "1"), - resource.TestCheckResourceAttr("aws_servicecatalog_portfolio.test", "tags.Key3", "Value Three"), + testAccCheckPortfolio(resourceName, &dpo), + resource.TestCheckResourceAttrSet(resourceName, "arn"), + resource.TestCheckResourceAttrSet(resourceName, "created_time"), + resource.TestCheckResourceAttr(resourceName, "name", name), + resource.TestCheckResourceAttr(resourceName, "description", "test-only-change-me"), + resource.TestCheckResourceAttr(resourceName, "provider_name", "test-c"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.Key3", "Value Three"), ), }, }, @@ -67,7 +74,9 @@ func TestAccAWSServiceCatalogPortfolio_Basic(t *testing.T) { func TestAccAWSServiceCatalogPortfolio_Disappears(t *testing.T) { name := acctest.RandString(5) + resourceName := "aws_servicecatalog_portfolio.test" var dpo servicecatalog.DescribePortfolioOutput + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -76,7 +85,7 @@ func TestAccAWSServiceCatalogPortfolio_Disappears(t *testing.T) { { Config: testAccCheckAwsServiceCatalogPortfolioResourceConfigBasic1(name), Check: resource.ComposeTestCheckFunc( - testAccCheckPortfolio("aws_servicecatalog_portfolio.test", &dpo), + testAccCheckPortfolio(resourceName, &dpo), testAccCheckServiceCatlaogPortfolioDisappears(&dpo), ), ExpectNonEmptyPlan: true, @@ -85,29 +94,6 @@ func TestAccAWSServiceCatalogPortfolio_Disappears(t *testing.T) { }) } -func TestAccAWSServiceCatalogPortfolio_Import(t *testing.T) { - resourceName := "aws_servicecatalog_portfolio.test" - - name := acctest.RandString(5) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckServiceCatlaogPortfolioDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckAwsServiceCatalogPortfolioResourceConfigBasic1(name), - }, - - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - func testAccCheckPortfolio(pr string, dpo *servicecatalog.DescribePortfolioOutput) resource.TestCheckFunc { return func(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).scconn