Merge pull request #10375 from hashicorp/parameter-group-tests

provider/aws: Randomize names for Parameter Group tests
This commit is contained in:
James Nugent 2016-11-26 18:47:05 +00:00 committed by GitHub
commit a8886012d1
2 changed files with 46 additions and 30 deletions

View File

@ -1,24 +1,28 @@
package aws
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAWSDBClusterParameterGroup_importBasic(t *testing.T) {
resourceName := "aws_rds_cluster_parameter_group.bar"
parameterGroupName := fmt.Sprintf("cluster-parameter-group-test-terraform-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBClusterParameterGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSDBClusterParameterGroupConfig,
{
Config: testAccAWSDBClusterParameterGroupConfig(parameterGroupName),
},
resource.TestStep{
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,

View File

@ -1,6 +1,7 @@
package aws
import (
"errors"
"fmt"
"testing"
"time"
@ -8,6 +9,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
@ -15,18 +17,20 @@ import (
func TestAccAWSDBClusterParameterGroup_basic(t *testing.T) {
var v rds.DBClusterParameterGroup
parameterGroupName := fmt.Sprintf("cluster-parameter-group-test-terraform-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBClusterParameterGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSDBClusterParameterGroupConfig,
{
Config: testAccAWSDBClusterParameterGroupConfig(parameterGroupName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v),
testAccCheckAWSDBClusterParameterGroupAttributes(&v),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "name", "cluster-parameter-group-test-terraform"),
"aws_rds_cluster_parameter_group.bar", "name", parameterGroupName),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "family", "aurora5.6"),
resource.TestCheckResourceAttr(
@ -47,13 +51,13 @@ func TestAccAWSDBClusterParameterGroup_basic(t *testing.T) {
"aws_rds_cluster_parameter_group.bar", "tags.%", "1"),
),
},
resource.TestStep{
Config: testAccAWSDBClusterParameterGroupAddParametersConfig,
{
Config: testAccAWSDBClusterParameterGroupAddParametersConfig(parameterGroupName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v),
testAccCheckAWSDBClusterParameterGroupAttributes(&v),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "name", "cluster-parameter-group-test-terraform"),
"aws_rds_cluster_parameter_group.bar", "name", parameterGroupName),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "family", "aurora5.6"),
resource.TestCheckResourceAttr(
@ -89,13 +93,15 @@ func TestAccAWSDBClusterParameterGroup_basic(t *testing.T) {
func TestAccAWSDBClusterParameterGroup_disappears(t *testing.T) {
var v rds.DBClusterParameterGroup
parameterGroupName := fmt.Sprintf("cluster-parameter-group-test-terraform-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBClusterParameterGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSDBClusterParameterGroupConfig,
{
Config: testAccAWSDBClusterParameterGroupConfig(parameterGroupName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v),
testAccAWSDBClusterParameterGroupDisappears(&v),
@ -109,18 +115,20 @@ func TestAccAWSDBClusterParameterGroup_disappears(t *testing.T) {
func TestAccAWSDBClusterParameterGroupOnly(t *testing.T) {
var v rds.DBClusterParameterGroup
parameterGroupName := fmt.Sprintf("cluster-parameter-group-test-tf-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBClusterParameterGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSDBClusterParameterGroupOnlyConfig,
{
Config: testAccAWSDBClusterParameterGroupOnlyConfig(parameterGroupName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v),
testAccCheckAWSDBClusterParameterGroupAttributes(&v),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "name", "cluster-parameter-group-test-terraform"),
"aws_rds_cluster_parameter_group.bar", "name", parameterGroupName),
resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "family", "aurora5.6"),
resource.TestCheckResourceAttr(
@ -166,7 +174,7 @@ func TestResourceAWSDBClusterParameterGroupName_validation(t *testing.T) {
_, errors := validateDbParamGroupName(tc.Value, "aws_rds_cluster_parameter_group_name")
if len(errors) != tc.ErrCount {
t.Fatalf("Expected the DB Cluster Parameter Group Name to trigger a validation error")
t.Fatal("Expected the DB Cluster Parameter Group Name to trigger a validation error")
}
}
}
@ -188,7 +196,7 @@ func testAccCheckAWSDBClusterParameterGroupDestroy(s *terraform.State) error {
if err == nil {
if len(resp.DBClusterParameterGroups) != 0 &&
*resp.DBClusterParameterGroups[0].DBClusterParameterGroupName == rs.Primary.ID {
return fmt.Errorf("DB Cluster Parameter Group still exists")
return errors.New("DB Cluster Parameter Group still exists")
}
}
@ -256,7 +264,7 @@ func testAccCheckAWSDBClusterParameterGroupExists(n string, v *rds.DBClusterPara
}
if rs.Primary.ID == "" {
return fmt.Errorf("No DB Cluster Parameter Group ID is set")
return errors.New("No DB Cluster Parameter Group ID is set")
}
conn := testAccProvider.Meta().(*AWSClient).rdsconn
@ -273,7 +281,7 @@ func testAccCheckAWSDBClusterParameterGroupExists(n string, v *rds.DBClusterPara
if len(resp.DBClusterParameterGroups) != 1 ||
*resp.DBClusterParameterGroups[0].DBClusterParameterGroupName != rs.Primary.ID {
return fmt.Errorf("DB Cluster Parameter Group not found")
return errors.New("DB Cluster Parameter Group not found")
}
*v = *resp.DBClusterParameterGroups[0]
@ -282,9 +290,10 @@ func testAccCheckAWSDBClusterParameterGroupExists(n string, v *rds.DBClusterPara
}
}
const testAccAWSDBClusterParameterGroupConfig = `
func testAccAWSDBClusterParameterGroupConfig(name string) string {
return fmt.Sprintf(`
resource "aws_rds_cluster_parameter_group" "bar" {
name = "cluster-parameter-group-test-terraform"
name = "%s"
family = "aurora5.6"
description = "Test cluster parameter group for terraform"
@ -307,11 +316,13 @@ resource "aws_rds_cluster_parameter_group" "bar" {
foo = "bar"
}
}
`
`, name)
}
const testAccAWSDBClusterParameterGroupAddParametersConfig = `
func testAccAWSDBClusterParameterGroupAddParametersConfig(name string) string {
return fmt.Sprintf(`
resource "aws_rds_cluster_parameter_group" "bar" {
name = "cluster-parameter-group-test-terraform"
name = "%s"
family = "aurora5.6"
description = "Test cluster parameter group for terraform"
@ -345,11 +356,12 @@ resource "aws_rds_cluster_parameter_group" "bar" {
baz = "foo"
}
}
`
const testAccAWSDBClusterParameterGroupOnlyConfig = `
resource "aws_rds_cluster_parameter_group" "bar" {
name = "cluster-parameter-group-test-terraform"
family = "aurora5.6"
`, name)
}
func testAccAWSDBClusterParameterGroupOnlyConfig(name string) string {
return fmt.Sprintf(`resource "aws_rds_cluster_parameter_group" "bar" {
name = "%s"
family = "aurora5.6"
}`, name)
}
`