diff --git a/aws/resource_aws_codecommit_repository_test.go b/aws/resource_aws_codecommit_repository_test.go index 6a8791d1bf51..074eb90fd1cb 100644 --- a/aws/resource_aws_codecommit_repository_test.go +++ b/aws/resource_aws_codecommit_repository_test.go @@ -12,9 +12,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccAWSCodeCommitRepository_importBasic(t *testing.T) { - resName := "aws_codecommit_repository.test" +func TestAccAWSCodeCommitRepository_basic(t *testing.T) { rInt := acctest.RandInt() + resourceName := "aws_codecommit_repository.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -23,9 +23,12 @@ func TestAccAWSCodeCommitRepository_importBasic(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccCodeCommitRepository_basic(rInt), + Check: resource.ComposeTestCheckFunc( + testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"), + ), }, { - ResourceName: resName, + ResourceName: resourceName, ImportState: true, ImportStateVerify: true, }, @@ -33,25 +36,10 @@ func TestAccAWSCodeCommitRepository_importBasic(t *testing.T) { }) } -func TestAccAWSCodeCommitRepository_basic(t *testing.T) { - rInt := acctest.RandInt() - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckCodeCommitRepositoryDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCodeCommitRepository_basic(rInt), - Check: resource.ComposeTestCheckFunc( - testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test"), - ), - }, - }, - }) -} - func TestAccAWSCodeCommitRepository_withChanges(t *testing.T) { rInt := acctest.RandInt() + resourceName := "aws_codecommit_repository.test" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -65,6 +53,11 @@ func TestAccAWSCodeCommitRepository_withChanges(t *testing.T) { "aws_codecommit_repository.test", "description", "This is a test description"), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, { Config: testAccCodeCommitRepository_withChanges(rInt), Check: resource.ComposeTestCheckFunc( @@ -79,6 +72,8 @@ func TestAccAWSCodeCommitRepository_withChanges(t *testing.T) { func TestAccAWSCodeCommitRepository_create_default_branch(t *testing.T) { rInt := acctest.RandInt() + resourceName := "aws_codecommit_repository.test" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -92,12 +87,20 @@ func TestAccAWSCodeCommitRepository_create_default_branch(t *testing.T) { "aws_codecommit_repository.test", "default_branch", "master"), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"default_branch"}, + }, }, }) } func TestAccAWSCodeCommitRepository_create_and_update_default_branch(t *testing.T) { rInt := acctest.RandInt() + resourceName := "aws_codecommit_repository.test" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -111,6 +114,11 @@ func TestAccAWSCodeCommitRepository_create_and_update_default_branch(t *testing. "aws_codecommit_repository.test", "default_branch"), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, { Config: testAccCodeCommitRepository_with_default_branch(rInt), Check: resource.ComposeTestCheckFunc( @@ -124,38 +132,43 @@ func TestAccAWSCodeCommitRepository_create_and_update_default_branch(t *testing. } func TestAccAWSCodeCommitRepository_tags(t *testing.T) { - rName := acctest.RandString(10) + resourceName := "aws_codecommit_repository.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - IDRefreshName: "aws_codecommit_repository.test_repository", + IDRefreshName: resourceName, Providers: testAccProviders, CheckDestroy: testAccCheckCodeCommitRepositoryDestroy, Steps: []resource.TestStep{ { Config: testAccAWSCodeCommitRepositoryConfigTags1(rName, "key1", "value1"), Check: resource.ComposeTestCheckFunc( - testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test_repository"), - resource.TestCheckResourceAttr("aws_codecommit_repository.test_repository", "tags.%", "1"), - resource.TestCheckResourceAttr("aws_codecommit_repository.test_repository", "tags.key1", "value1"), + testAccCheckCodeCommitRepositoryExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, { Config: testAccAWSCodeCommitRepositoryConfigTags2(rName, "key1", "value1updated", "key2", "value2"), Check: resource.ComposeTestCheckFunc( - testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test_repository"), - resource.TestCheckResourceAttr("aws_codecommit_repository.test_repository", "tags.%", "2"), - resource.TestCheckResourceAttr("aws_codecommit_repository.test_repository", "tags.key1", "value1updated"), - resource.TestCheckResourceAttr("aws_codecommit_repository.test_repository", "tags.key2", "value2"), + testAccCheckCodeCommitRepositoryExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), ), }, { Config: testAccAWSCodeCommitRepositoryConfigTags1(rName, "key2", "value2"), Check: resource.ComposeTestCheckFunc( - testAccCheckCodeCommitRepositoryExists("aws_codecommit_repository.test_repository"), - resource.TestCheckResourceAttr("aws_codecommit_repository.test_repository", "tags.%", "1"), - resource.TestCheckResourceAttr("aws_codecommit_repository.test_repository", "tags.key2", "value2"), + testAccCheckCodeCommitRepositoryExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), ), }, }, @@ -249,7 +262,7 @@ resource "aws_codecommit_repository" "test" { func testAccAWSCodeCommitRepositoryConfigTags1(r, tag1Key, tag1Value string) string { return fmt.Sprintf(` -resource "aws_codecommit_repository" "test_repository" { +resource "aws_codecommit_repository" "test" { repository_name = "terraform-test-%s" tags = { %q = %q @@ -259,7 +272,7 @@ resource "aws_codecommit_repository" "test_repository" { func testAccAWSCodeCommitRepositoryConfigTags2(r, tag1Key, tag1Value, tag2Key, tag2Value string) string { return fmt.Sprintf(` -resource "aws_codecommit_repository" "test_repository" { +resource "aws_codecommit_repository" "test" { repository_name = "terraform-test-%s" tags = { %q = %q