Skip to content

Commit

Permalink
Merge pull request #14007 from terraform-providers/td-singular-data-s…
Browse files Browse the repository at this point in the history
…ource-ecr-repo

data-source/ecr_repository: add non-existent acctest
  • Loading branch information
anGie44 authored Jul 17, 2020
2 parents 594a1e1 + 4e0be60 commit b4d84e9
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions aws/data_source_aws_ecr_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (

func TestAccAWSEcrDataSource_ecrRepository(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "data.aws_ecr_repository.default"
resourceName := "aws_ecr_repository.test"
dataSourceName := "data.aws_ecr_repository.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -20,20 +21,39 @@ func TestAccAWSEcrDataSource_ecrRepository(t *testing.T) {
{
Config: testAccCheckAwsEcrRepositoryDataSourceConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "ecr", regexp.MustCompile(fmt.Sprintf("repository/%s$", rName))),
resource.TestCheckResourceAttrSet(resourceName, "registry_id"),
resource.TestMatchResourceAttr(resourceName, "repository_url", regexp.MustCompile(fmt.Sprintf(`^\d+\.dkr\.ecr\.%s\.amazonaws\.com/%s$`, testAccGetRegion(), rName))),
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.Usage", "original"),
resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"),
resource.TestCheckResourceAttrPair(resourceName, "registry_id", dataSourceName, "registry_id"),
resource.TestCheckResourceAttrPair(resourceName, "repository_url", dataSourceName, "repository_url"),
resource.TestCheckResourceAttrPair(resourceName, "tags", dataSourceName, "tags"),
),
},
},
})
}

func TestAccAWSEcrDataSource_nonExistent(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckAwsEcrRepositoryDataSourceConfig_NonExistent,
ExpectError: regexp.MustCompile(`not found`),
},
},
})
}

const testAccCheckAwsEcrRepositoryDataSourceConfig_NonExistent = `
data "aws_ecr_repository" "test" {
name = "tf-acc-test-non-existent"
}
`

func testAccCheckAwsEcrRepositoryDataSourceConfig(rName string) string {
return fmt.Sprintf(`
resource "aws_ecr_repository" "default" {
resource "aws_ecr_repository" "test" {
name = %q
tags = {
Expand All @@ -42,8 +62,8 @@ resource "aws_ecr_repository" "default" {
}
}
data "aws_ecr_repository" "default" {
name = "${aws_ecr_repository.default.name}"
data "aws_ecr_repository" "test" {
name = "${aws_ecr_repository.test.name}"
}
`, rName)
}

0 comments on commit b4d84e9

Please sign in to comment.