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

Import test refactor for codecommit #10604

Merged
merged 1 commit into from
Oct 29, 2019
Merged
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
81 changes: 47 additions & 34 deletions aws/resource_aws_codecommit_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand All @@ -23,35 +23,23 @@ 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,
},
},
})
}

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,
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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"),
),
},
},
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down