Skip to content

Commit

Permalink
Merge pull request hashicorp#1236 from terraform-providers/b-ecr-rand…
Browse files Browse the repository at this point in the history
…omization

r/ecr_repository: Randomize names in tests
  • Loading branch information
radeksimko committed Jul 26, 2017
2 parents e0c56cc + d88d22a commit 7b6bc1b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
4 changes: 3 additions & 1 deletion aws/import_aws_ecr_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ package aws
import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAWSEcrRepository_importBasic(t *testing.T) {
resourceName := "aws_ecr_repository.default"
randString := acctest.RandString(10)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcrRepositoryDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSEcrRepository,
Config: testAccAWSEcrRepository(randString),
},

resource.TestStep{
Expand Down
27 changes: 18 additions & 9 deletions aws/resource_aws_ecr_repository_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ecr"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccAWSEcrRepositoryPolicy_basic(t *testing.T) {
randString := acctest.RandString(10)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcrRepositoryPolicyDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSEcrRepositoryPolicy,
Config: testAccAWSEcrRepositoryPolicy(randString),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcrRepositoryPolicyExists("aws_ecr_repository_policy.default"),
),
Expand All @@ -28,13 +31,15 @@ func TestAccAWSEcrRepositoryPolicy_basic(t *testing.T) {
}

func TestAccAWSEcrRepositoryPolicy_iam(t *testing.T) {
randString := acctest.RandString(10)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcrRepositoryPolicyDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSEcrRepositoryPolicyWithIAMRole,
Config: testAccAWSEcrRepositoryPolicyWithIAMRole(randString),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcrRepositoryPolicyExists("aws_ecr_repository_policy.default"),
),
Expand Down Expand Up @@ -77,14 +82,15 @@ func testAccCheckAWSEcrRepositoryPolicyExists(name string) resource.TestCheckFun
}
}

var testAccAWSEcrRepositoryPolicy = `
func testAccAWSEcrRepositoryPolicy(randString string) string {
return fmt.Sprintf(`
# ECR initially only available in us-east-1
# https://aws.amazon.com/blogs/aws/ec2-container-registry-now-generally-available/
provider "aws" {
region = "us-east-1"
}
resource "aws_ecr_repository" "foo" {
name = "bar"
name = "tf-acc-test-ecr-%s"
}
resource "aws_ecr_repository_policy" "default" {
Expand All @@ -105,23 +111,25 @@ resource "aws_ecr_repository_policy" "default" {
}
EOF
}
`
`, randString)
}

// testAccAWSEcrRepositoryPolicyWithIAMRole creates a new IAM Role and tries
// to use it's ARN in an ECR Repository Policy. IAM changes need some time to
// be propagated to other services - like ECR. So the following code should
// exercise our retry logic, since we try to use the new resource instantly.
var testAccAWSEcrRepositoryPolicyWithIAMRole = `
func testAccAWSEcrRepositoryPolicyWithIAMRole(randString string) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-east-1"
}
resource "aws_ecr_repository" "foo" {
name = "bar"
name = "tf-acc-test-ecr-%s"
}
resource "aws_iam_role" "foo" {
name = "bar"
name = "tf-acc-test-ecr-%s"
assume_role_policy = <<EOF
{
Expand Down Expand Up @@ -159,4 +167,5 @@ resource "aws_ecr_repository_policy" "default" {
}
EOF
}
`
`, randString, randString)
}
13 changes: 9 additions & 4 deletions aws/resource_aws_ecr_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ecr"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccAWSEcrRepository_basic(t *testing.T) {
randString := acctest.RandString(10)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcrRepositoryDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEcrRepository,
Config: testAccAWSEcrRepository(randString),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcrRepositoryExists("aws_ecr_repository.default"),
),
Expand Down Expand Up @@ -69,8 +72,10 @@ func testAccCheckAWSEcrRepositoryExists(name string) resource.TestCheckFunc {
}
}

var testAccAWSEcrRepository = `
func testAccAWSEcrRepository(randString string) string {
return fmt.Sprintf(`
resource "aws_ecr_repository" "default" {
name = "foo-repository-terraform"
name = "tf-acc-test-ecr-%s"
}
`, randString)
}
`

0 comments on commit 7b6bc1b

Please sign in to comment.