Merge pull request #5116 from hashicorp/b-aws-acc-tests
provider/aws: Update some tests to introduce more randomization
This commit is contained in:
commit
52e0cd82bd
|
@ -8,6 +8,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
|
||||
|
@ -73,12 +74,14 @@ func TestAccAWSDBInstanceSnapshot(t *testing.T) {
|
|||
var snap rds.DBInstance
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
// testAccCheckAWSDBInstanceSnapshot verifies a database snapshot is
|
||||
// created, and subequently deletes it
|
||||
CheckDestroy: testAccCheckAWSDBInstanceSnapshot,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccSnapshotInstanceConfig,
|
||||
Config: testAccSnapshotInstanceConfig(),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSDBInstanceExists("aws_db_instance.snapshot", &snap),
|
||||
),
|
||||
|
@ -367,12 +370,13 @@ func testAccReplicaInstanceConfig(val int) string {
|
|||
`, val, val)
|
||||
}
|
||||
|
||||
var testAccSnapshotInstanceConfig = `
|
||||
func testAccSnapshotInstanceConfig() string {
|
||||
return fmt.Sprintf(`
|
||||
provider "aws" {
|
||||
region = "us-east-1"
|
||||
}
|
||||
resource "aws_db_instance" "snapshot" {
|
||||
identifier = "foobarbaz-test-terraform-snapshot-1"
|
||||
identifier = "tf-snapshot-%d"
|
||||
|
||||
allocated_storage = 5
|
||||
engine = "mysql"
|
||||
|
@ -388,8 +392,8 @@ resource "aws_db_instance" "snapshot" {
|
|||
|
||||
skip_final_snapshot = false
|
||||
final_snapshot_identifier = "foobarbaz-test-terraform-final-snapshot-1"
|
||||
}`, acctest.RandInt())
|
||||
}
|
||||
`
|
||||
|
||||
var testAccNoSnapshotInstanceConfig = `
|
||||
provider "aws" {
|
||||
|
|
|
@ -340,7 +340,7 @@ func resourceAwsDirectoryServiceDirectoryCreate(d *schema.ResourceData, meta int
|
|||
}
|
||||
if _, err := stateConf.WaitForState(); err != nil {
|
||||
return fmt.Errorf(
|
||||
"Error waiting for Directory Service (%s) to become available: %#v",
|
||||
"Error waiting for Directory Service (%s) to become available: %s",
|
||||
d.Id(), err)
|
||||
}
|
||||
|
||||
|
@ -404,7 +404,7 @@ func resourceAwsDirectoryServiceDirectoryRead(d *schema.ResourceData, meta inter
|
|||
}
|
||||
|
||||
dir := out.DirectoryDescriptions[0]
|
||||
log.Printf("[DEBUG] Received DS directory: %s", *dir)
|
||||
log.Printf("[DEBUG] Received DS directory: %s", dir)
|
||||
|
||||
d.Set("access_url", *dir.AccessUrl)
|
||||
d.Set("alias", *dir.Alias)
|
||||
|
|
|
@ -2,11 +2,13 @@ package aws
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/iam"
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
@ -14,32 +16,41 @@ import (
|
|||
func TestAccAWSGroupMembership_basic(t *testing.T) {
|
||||
var group iam.GetGroupOutput
|
||||
|
||||
rString := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
|
||||
configBase := fmt.Sprintf(testAccAWSGroupMemberConfig, rString, rString, rString)
|
||||
configUpdate := fmt.Sprintf(testAccAWSGroupMemberConfigUpdate, rString, rString, rString, rString)
|
||||
configUpdateDown := fmt.Sprintf(testAccAWSGroupMemberConfigUpdateDown, rString, rString, rString)
|
||||
|
||||
testUser := fmt.Sprintf("test-user-%s", rString)
|
||||
testUserTwo := fmt.Sprintf("test-user-two-%s", rString)
|
||||
testUserThree := fmt.Sprintf("test-user-three-%s", rString)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckAWSGroupMembershipDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccAWSGroupMemberConfig,
|
||||
Config: configBase,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSGroupMembershipExists("aws_iam_group_membership.team", &group),
|
||||
testAccCheckAWSGroupMembershipAttributes(&group, []string{"test-user"}),
|
||||
testAccCheckAWSGroupMembershipAttributes(&group, []string{testUser}),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: testAccAWSGroupMemberConfigUpdate,
|
||||
Config: configUpdate,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSGroupMembershipExists("aws_iam_group_membership.team", &group),
|
||||
testAccCheckAWSGroupMembershipAttributes(&group, []string{"test-user-two", "test-user-three"}),
|
||||
testAccCheckAWSGroupMembershipAttributes(&group, []string{testUserTwo, testUserThree}),
|
||||
),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
Config: testAccAWSGroupMemberConfigUpdateDown,
|
||||
Config: configUpdateDown,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSGroupMembershipExists("aws_iam_group_membership.team", &group),
|
||||
testAccCheckAWSGroupMembershipAttributes(&group, []string{"test-user-three"}),
|
||||
testAccCheckAWSGroupMembershipAttributes(&group, []string{testUserThree}),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -103,8 +114,8 @@ func testAccCheckAWSGroupMembershipExists(n string, g *iam.GetGroupOutput) resou
|
|||
|
||||
func testAccCheckAWSGroupMembershipAttributes(group *iam.GetGroupOutput, users []string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
if *group.Group.GroupName != "test-group" {
|
||||
return fmt.Errorf("Bad group membership: expected %s, got %s", "test-group", *group.Group.GroupName)
|
||||
if !strings.Contains(*group.Group.GroupName, "test-group") {
|
||||
return fmt.Errorf("Bad group membership: expected %d, got %d", "test-group", *group.Group.GroupName)
|
||||
}
|
||||
|
||||
uc := len(users)
|
||||
|
@ -125,17 +136,17 @@ func testAccCheckAWSGroupMembershipAttributes(group *iam.GetGroupOutput, users [
|
|||
|
||||
const testAccAWSGroupMemberConfig = `
|
||||
resource "aws_iam_group" "group" {
|
||||
name = "test-group"
|
||||
name = "test-group-%s"
|
||||
path = "/"
|
||||
}
|
||||
|
||||
resource "aws_iam_user" "user" {
|
||||
name = "test-user"
|
||||
name = "test-user-%s"
|
||||
path = "/"
|
||||
}
|
||||
|
||||
resource "aws_iam_group_membership" "team" {
|
||||
name = "tf-testing-group-membership"
|
||||
name = "tf-testing-group-membership-%s"
|
||||
users = ["${aws_iam_user.user.name}"]
|
||||
group = "${aws_iam_group.group.name}"
|
||||
}
|
||||
|
@ -143,27 +154,27 @@ resource "aws_iam_group_membership" "team" {
|
|||
|
||||
const testAccAWSGroupMemberConfigUpdate = `
|
||||
resource "aws_iam_group" "group" {
|
||||
name = "test-group"
|
||||
name = "test-group-%s"
|
||||
path = "/"
|
||||
}
|
||||
|
||||
resource "aws_iam_user" "user" {
|
||||
name = "test-user"
|
||||
name = "test-user-%s"
|
||||
path = "/"
|
||||
}
|
||||
|
||||
resource "aws_iam_user" "user_two" {
|
||||
name = "test-user-two"
|
||||
name = "test-user-two-%s"
|
||||
path = "/"
|
||||
}
|
||||
|
||||
resource "aws_iam_user" "user_three" {
|
||||
name = "test-user-three"
|
||||
name = "test-user-three-%s"
|
||||
path = "/"
|
||||
}
|
||||
|
||||
resource "aws_iam_group_membership" "team" {
|
||||
name = "tf-testing-group-membership"
|
||||
name = "tf-testing-group-membership-%s"
|
||||
users = [
|
||||
"${aws_iam_user.user_two.name}",
|
||||
"${aws_iam_user.user_three.name}",
|
||||
|
@ -174,17 +185,17 @@ resource "aws_iam_group_membership" "team" {
|
|||
|
||||
const testAccAWSGroupMemberConfigUpdateDown = `
|
||||
resource "aws_iam_group" "group" {
|
||||
name = "test-group"
|
||||
name = "test-group-%s"
|
||||
path = "/"
|
||||
}
|
||||
|
||||
resource "aws_iam_user" "user_three" {
|
||||
name = "test-user-three"
|
||||
name = "test-user-three-%s"
|
||||
path = "/"
|
||||
}
|
||||
|
||||
resource "aws_iam_group_membership" "team" {
|
||||
name = "tf-testing-group-membership"
|
||||
name = "tf-testing-group-membership-%s"
|
||||
users = [
|
||||
"${aws_iam_user.user_three.name}",
|
||||
]
|
||||
|
|
|
@ -2,11 +2,10 @@ package aws
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
|
||||
|
@ -119,16 +118,16 @@ func testAccCheckAWSClusterInstanceExists(n string, v *rds.DBInstance) resource.
|
|||
var testAccAWSClusterInstanceConfig = fmt.Sprintf(`
|
||||
resource "aws_rds_cluster" "default" {
|
||||
cluster_identifier = "tf-aurora-cluster-test-%d"
|
||||
availability_zones = ["us-west-2a","us-west-2b","us-west-2c"]
|
||||
database_name = "mydb"
|
||||
master_username = "foo"
|
||||
master_password = "mustbeeightcharaters"
|
||||
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
|
||||
database_name = "mydb"
|
||||
master_username = "foo"
|
||||
master_password = "mustbeeightcharaters"
|
||||
}
|
||||
|
||||
resource "aws_rds_cluster_instance" "cluster_instances" {
|
||||
identifier = "aurora-cluster-test-instance"
|
||||
cluster_identifier = "${aws_rds_cluster.default.id}"
|
||||
instance_class = "db.r3.large"
|
||||
identifier = "tf-cluster-instance-%d"
|
||||
cluster_identifier = "${aws_rds_cluster.default.id}"
|
||||
instance_class = "db.r3.large"
|
||||
}
|
||||
|
||||
`, rand.New(rand.NewSource(time.Now().UnixNano())).Int())
|
||||
`, acctest.RandInt(), acctest.RandInt())
|
||||
|
|
Loading…
Reference in New Issue