provider/aws: Improve IAM Group AccTests
Improve the iam_group acceptance tests. Previously, the iam_group would overlap when running our tests in parallel. This fixes that.
This commit is contained in:
parent
aa7aa19592
commit
643a52ab3e
|
@ -3,10 +3,12 @@ package aws
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
)
|
||||
|
||||
func TestAccAWSIAMGroup_importBasic(t *testing.T) {
|
||||
rInt := acctest.RandInt()
|
||||
resourceName := "aws_iam_group.group"
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
|
@ -14,11 +16,11 @@ func TestAccAWSIAMGroup_importBasic(t *testing.T) {
|
|||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckAWSGroupDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccAWSGroupConfig,
|
||||
{
|
||||
Config: testAccAWSGroupConfig(rInt),
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
{
|
||||
ResourceName: resourceName,
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"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"
|
||||
)
|
||||
|
@ -24,9 +26,9 @@ func TestValidateIamGroupName(t *testing.T) {
|
|||
"test+group@hashicorp.com",
|
||||
}
|
||||
for _, v := range validNames {
|
||||
_, errors := validateAwsIamGroupName(v, "name")
|
||||
if len(errors) != 0 {
|
||||
t.Fatalf("%q should be a valid IAM Group name: %q", v, errors)
|
||||
_, errs := validateAwsIamGroupName(v, "name")
|
||||
if len(errs) != 0 {
|
||||
t.Fatalf("%q should be a valid IAM Group name: %q", v, errs)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,8 +43,8 @@ func TestValidateIamGroupName(t *testing.T) {
|
|||
"slash-at-the-end/",
|
||||
}
|
||||
for _, v := range invalidNames {
|
||||
_, errors := validateAwsIamGroupName(v, "name")
|
||||
if len(errors) == 0 {
|
||||
_, errs := validateAwsIamGroupName(v, "name")
|
||||
if len(errs) == 0 {
|
||||
t.Fatalf("%q should be an invalid IAM Group name", v)
|
||||
}
|
||||
}
|
||||
|
@ -50,24 +52,25 @@ func TestValidateIamGroupName(t *testing.T) {
|
|||
|
||||
func TestAccAWSIAMGroup_basic(t *testing.T) {
|
||||
var conf iam.GetGroupOutput
|
||||
rInt := acctest.RandInt()
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckAWSGroupDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccAWSGroupConfig,
|
||||
{
|
||||
Config: testAccAWSGroupConfig(rInt),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSGroupExists("aws_iam_group.group", &conf),
|
||||
testAccCheckAWSGroupAttributes(&conf, "test-group", "/"),
|
||||
testAccCheckAWSGroupAttributes(&conf, fmt.Sprintf("test-group-%d", rInt), "/"),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: testAccAWSGroupConfig2,
|
||||
{
|
||||
Config: testAccAWSGroupConfig2(rInt),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSGroupExists("aws_iam_group.group2", &conf),
|
||||
testAccCheckAWSGroupAttributes(&conf, "test-group2", "/funnypath/"),
|
||||
testAccCheckAWSGroupAttributes(&conf, fmt.Sprintf("test-group-%d-2", rInt), "/funnypath/"),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -87,7 +90,7 @@ func testAccCheckAWSGroupDestroy(s *terraform.State) error {
|
|||
GroupName: aws.String(rs.Primary.ID),
|
||||
})
|
||||
if err == nil {
|
||||
return fmt.Errorf("still exist.")
|
||||
return errors.New("still exist.")
|
||||
}
|
||||
|
||||
// Verify the error is what we want
|
||||
|
@ -111,7 +114,7 @@ func testAccCheckAWSGroupExists(n string, res *iam.GetGroupOutput) resource.Test
|
|||
}
|
||||
|
||||
if rs.Primary.ID == "" {
|
||||
return fmt.Errorf("No Group name is set")
|
||||
return errors.New("No Group name is set")
|
||||
}
|
||||
|
||||
iamconn := testAccProvider.Meta().(*AWSClient).iamconn
|
||||
|
@ -143,15 +146,18 @@ func testAccCheckAWSGroupAttributes(group *iam.GetGroupOutput, name string, path
|
|||
}
|
||||
}
|
||||
|
||||
const testAccAWSGroupConfig = `
|
||||
func testAccAWSGroupConfig(rInt int) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "aws_iam_group" "group" {
|
||||
name = "test-group"
|
||||
name = "test-group-%d"
|
||||
path = "/"
|
||||
}`, rInt)
|
||||
}
|
||||
`
|
||||
const testAccAWSGroupConfig2 = `
|
||||
|
||||
func testAccAWSGroupConfig2(rInt int) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "aws_iam_group" "group2" {
|
||||
name = "test-group2"
|
||||
name = "test-group-%d-2"
|
||||
path = "/funnypath/"
|
||||
}`, rInt)
|
||||
}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue