Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Acceptance test import refactor for service resources #9963

Merged
merged 1 commit into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 44 additions & 44 deletions aws/resource_aws_service_discovery_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"),
),
},
},
Expand All @@ -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,
Expand All @@ -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"),
),
},
},
Expand All @@ -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,
Expand All @@ -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,
Expand Down
84 changes: 35 additions & 49 deletions aws/resource_aws_servicecatalog_portfolio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"),
),
},
},
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down