Skip to content

Commit

Permalink
Add acceptance test for import + randomization
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Jan 12, 2018
1 parent 0fa0484 commit 9122efa
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions aws/resource_aws_ecs_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,56 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccAWSEcsCluster_basic(t *testing.T) {
rString := acctest.RandString(8)
clusterName := fmt.Sprintf("tf-acc-cluster-basic-%s", rString)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcsClusterDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSEcsCluster,
Config: testAccAWSEcsCluster(clusterName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsClusterExists("aws_ecs_cluster.foo"),
resource.TestMatchResourceAttr("aws_ecs_cluster.foo", "arn",
regexp.MustCompile("^arn:aws:ecs:[a-z0-9-]+:[0-9]{12}:cluster/red-grapes$")),
regexp.MustCompile("^arn:aws:ecs:[a-z0-9-]+:[0-9]{12}:cluster/"+clusterName+"$")),
),
},
},
})
}

func TestAccAWSEcsCluster_importBasic(t *testing.T) {
rString := acctest.RandString(8)
clusterName := fmt.Sprintf("tf-acc-cluster-import-%s", rString)

resourceName := "aws_ecs_cluster.foo"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcsClusterDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSEcsCluster(clusterName),
},
resource.TestStep{
ResourceName: resourceName,
ImportStateId: clusterName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckAWSEcsClusterDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ecsconn

Expand Down Expand Up @@ -66,8 +94,10 @@ func testAccCheckAWSEcsClusterExists(name string) resource.TestCheckFunc {
}
}

var testAccAWSEcsCluster = `
func testAccAWSEcsCluster(clusterName string) string {
return fmt.Sprintf(`
resource "aws_ecs_cluster" "foo" {
name = "red-grapes"
name = "%s"
}
`, clusterName)
}
`

0 comments on commit 9122efa

Please sign in to comment.