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

View File

@ -1,6 +1,7 @@
package aws package aws
import ( import (
"errors"
"fmt" "fmt"
"testing" "testing"
"time" "time"
@ -8,6 +9,7 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/rds" "github.com/aws/aws-sdk-go/service/rds"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -15,18 +17,20 @@ import (
func TestAccAWSDBClusterParameterGroup_basic(t *testing.T) { func TestAccAWSDBClusterParameterGroup_basic(t *testing.T) {
var v rds.DBClusterParameterGroup var v rds.DBClusterParameterGroup
parameterGroupName := fmt.Sprintf("cluster-parameter-group-test-terraform-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBClusterParameterGroupDestroy, CheckDestroy: testAccCheckAWSDBClusterParameterGroupDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSDBClusterParameterGroupConfig, Config: testAccAWSDBClusterParameterGroupConfig(parameterGroupName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v), testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v),
testAccCheckAWSDBClusterParameterGroupAttributes(&v), testAccCheckAWSDBClusterParameterGroupAttributes(&v),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "name", "cluster-parameter-group-test-terraform"), "aws_rds_cluster_parameter_group.bar", "name", parameterGroupName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "family", "aurora5.6"), "aws_rds_cluster_parameter_group.bar", "family", "aurora5.6"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -47,13 +51,13 @@ func TestAccAWSDBClusterParameterGroup_basic(t *testing.T) {
"aws_rds_cluster_parameter_group.bar", "tags.%", "1"), "aws_rds_cluster_parameter_group.bar", "tags.%", "1"),
), ),
}, },
resource.TestStep{ {
Config: testAccAWSDBClusterParameterGroupAddParametersConfig, Config: testAccAWSDBClusterParameterGroupAddParametersConfig(parameterGroupName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v), testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v),
testAccCheckAWSDBClusterParameterGroupAttributes(&v), testAccCheckAWSDBClusterParameterGroupAttributes(&v),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "name", "cluster-parameter-group-test-terraform"), "aws_rds_cluster_parameter_group.bar", "name", parameterGroupName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "family", "aurora5.6"), "aws_rds_cluster_parameter_group.bar", "family", "aurora5.6"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -89,13 +93,15 @@ func TestAccAWSDBClusterParameterGroup_basic(t *testing.T) {
func TestAccAWSDBClusterParameterGroup_disappears(t *testing.T) { func TestAccAWSDBClusterParameterGroup_disappears(t *testing.T) {
var v rds.DBClusterParameterGroup var v rds.DBClusterParameterGroup
parameterGroupName := fmt.Sprintf("cluster-parameter-group-test-terraform-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBClusterParameterGroupDestroy, CheckDestroy: testAccCheckAWSDBClusterParameterGroupDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSDBClusterParameterGroupConfig, Config: testAccAWSDBClusterParameterGroupConfig(parameterGroupName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v), testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v),
testAccAWSDBClusterParameterGroupDisappears(&v), testAccAWSDBClusterParameterGroupDisappears(&v),
@ -109,18 +115,20 @@ func TestAccAWSDBClusterParameterGroup_disappears(t *testing.T) {
func TestAccAWSDBClusterParameterGroupOnly(t *testing.T) { func TestAccAWSDBClusterParameterGroupOnly(t *testing.T) {
var v rds.DBClusterParameterGroup var v rds.DBClusterParameterGroup
parameterGroupName := fmt.Sprintf("cluster-parameter-group-test-tf-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBClusterParameterGroupDestroy, CheckDestroy: testAccCheckAWSDBClusterParameterGroupDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSDBClusterParameterGroupOnlyConfig, Config: testAccAWSDBClusterParameterGroupOnlyConfig(parameterGroupName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v), testAccCheckAWSDBClusterParameterGroupExists("aws_rds_cluster_parameter_group.bar", &v),
testAccCheckAWSDBClusterParameterGroupAttributes(&v), testAccCheckAWSDBClusterParameterGroupAttributes(&v),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "name", "cluster-parameter-group-test-terraform"), "aws_rds_cluster_parameter_group.bar", "name", parameterGroupName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_rds_cluster_parameter_group.bar", "family", "aurora5.6"), "aws_rds_cluster_parameter_group.bar", "family", "aurora5.6"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -166,7 +174,7 @@ func TestResourceAWSDBClusterParameterGroupName_validation(t *testing.T) {
_, errors := validateDbParamGroupName(tc.Value, "aws_rds_cluster_parameter_group_name") _, errors := validateDbParamGroupName(tc.Value, "aws_rds_cluster_parameter_group_name")
if len(errors) != tc.ErrCount { 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 err == nil {
if len(resp.DBClusterParameterGroups) != 0 && if len(resp.DBClusterParameterGroups) != 0 &&
*resp.DBClusterParameterGroups[0].DBClusterParameterGroupName == rs.Primary.ID { *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 == "" { 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 conn := testAccProvider.Meta().(*AWSClient).rdsconn
@ -273,7 +281,7 @@ func testAccCheckAWSDBClusterParameterGroupExists(n string, v *rds.DBClusterPara
if len(resp.DBClusterParameterGroups) != 1 || if len(resp.DBClusterParameterGroups) != 1 ||
*resp.DBClusterParameterGroups[0].DBClusterParameterGroupName != rs.Primary.ID { *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] *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" { resource "aws_rds_cluster_parameter_group" "bar" {
name = "cluster-parameter-group-test-terraform" name = "%s"
family = "aurora5.6" family = "aurora5.6"
description = "Test cluster parameter group for terraform" description = "Test cluster parameter group for terraform"
@ -307,11 +316,13 @@ resource "aws_rds_cluster_parameter_group" "bar" {
foo = "bar" foo = "bar"
} }
} }
` `, name)
}
const testAccAWSDBClusterParameterGroupAddParametersConfig = ` func testAccAWSDBClusterParameterGroupAddParametersConfig(name string) string {
return fmt.Sprintf(`
resource "aws_rds_cluster_parameter_group" "bar" { resource "aws_rds_cluster_parameter_group" "bar" {
name = "cluster-parameter-group-test-terraform" name = "%s"
family = "aurora5.6" family = "aurora5.6"
description = "Test cluster parameter group for terraform" description = "Test cluster parameter group for terraform"
@ -345,11 +356,12 @@ resource "aws_rds_cluster_parameter_group" "bar" {
baz = "foo" baz = "foo"
} }
} }
` `, name)
}
const testAccAWSDBClusterParameterGroupOnlyConfig = `
resource "aws_rds_cluster_parameter_group" "bar" { func testAccAWSDBClusterParameterGroupOnlyConfig(name string) string {
name = "cluster-parameter-group-test-terraform" return fmt.Sprintf(`resource "aws_rds_cluster_parameter_group" "bar" {
family = "aurora5.6" name = "%s"
family = "aurora5.6"
}`, name)
} }
`