provider/aws: More randomization so our tests can run in parallel

This commit is contained in:
clint shryock 2016-12-15 16:33:10 -06:00
parent 442f6de8c9
commit 8d2e61e88d
4 changed files with 43 additions and 19 deletions

View File

@ -1,21 +1,24 @@
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 TestAccAWSEFSMountTarget_importBasic(t *testing.T) { func TestAccAWSEFSMountTarget_importBasic(t *testing.T) {
resourceName := "aws_efs_mount_target.alpha" resourceName := "aws_efs_mount_target.alpha"
ct := fmt.Sprintf("createtoken-%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: testAccCheckEfsMountTargetDestroy, CheckDestroy: testAccCheckEfsMountTargetDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccAWSEFSMountTargetConfig, Config: testAccAWSEFSMountTargetConfig(ct),
}, },
resource.TestStep{ resource.TestStep{

View File

@ -1,21 +1,25 @@
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 TestAccAWSFlowLog_importBasic(t *testing.T) { func TestAccAWSFlowLog_importBasic(t *testing.T) {
resourceName := "aws_flow_log.test_flow_log" resourceName := "aws_flow_log.test_flow_log"
fln := fmt.Sprintf("tf-test-fl-%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: testAccCheckFlowLogDestroy, CheckDestroy: testAccCheckFlowLogDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccFlowLogConfig_basic, Config: testAccFlowLogConfig_basic(fln),
}, },
resource.TestStep{ resource.TestStep{

View File

@ -10,12 +10,14 @@ import (
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/efs" "github.com/aws/aws-sdk-go/service/efs"
"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"
) )
func TestAccAWSEFSMountTarget_basic(t *testing.T) { func TestAccAWSEFSMountTarget_basic(t *testing.T) {
var mount efs.MountTargetDescription var mount efs.MountTargetDescription
ct := fmt.Sprintf("createtoken-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -23,7 +25,7 @@ func TestAccAWSEFSMountTarget_basic(t *testing.T) {
CheckDestroy: testAccCheckEfsMountTargetDestroy, CheckDestroy: testAccCheckEfsMountTargetDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccAWSEFSMountTargetConfig, Config: testAccAWSEFSMountTargetConfig(ct),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckEfsMountTarget( testAccCheckEfsMountTarget(
"aws_efs_mount_target.alpha", "aws_efs_mount_target.alpha",
@ -37,7 +39,7 @@ func TestAccAWSEFSMountTarget_basic(t *testing.T) {
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccAWSEFSMountTargetConfigModified, Config: testAccAWSEFSMountTargetConfigModified(ct),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckEfsMountTarget( testAccCheckEfsMountTarget(
"aws_efs_mount_target.alpha", "aws_efs_mount_target.alpha",
@ -66,13 +68,15 @@ func TestAccAWSEFSMountTarget_basic(t *testing.T) {
func TestAccAWSEFSMountTarget_disappears(t *testing.T) { func TestAccAWSEFSMountTarget_disappears(t *testing.T) {
var mount efs.MountTargetDescription var mount efs.MountTargetDescription
ct := fmt.Sprintf("createtoken-%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: testAccCheckVpnGatewayDestroy, CheckDestroy: testAccCheckVpnGatewayDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccAWSEFSMountTargetConfig, Config: testAccAWSEFSMountTargetConfig(ct),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckEfsMountTarget( testAccCheckEfsMountTarget(
"aws_efs_mount_target.alpha", "aws_efs_mount_target.alpha",
@ -218,9 +222,10 @@ func testAccAWSEFSMountTargetDisappears(mount *efs.MountTargetDescription) resou
} }
const testAccAWSEFSMountTargetConfig = ` func testAccAWSEFSMountTargetConfig(ct string) string {
return fmt.Sprintf(`
resource "aws_efs_file_system" "foo" { resource "aws_efs_file_system" "foo" {
creation_token = "radeksimko" creation_token = "%s"
} }
resource "aws_efs_mount_target" "alpha" { resource "aws_efs_mount_target" "alpha" {
@ -237,11 +242,13 @@ resource "aws_subnet" "alpha" {
availability_zone = "us-west-2a" availability_zone = "us-west-2a"
cidr_block = "10.0.1.0/24" cidr_block = "10.0.1.0/24"
} }
` `, ct)
}
const testAccAWSEFSMountTargetConfigModified = ` func testAccAWSEFSMountTargetConfigModified(ct string) string {
return fmt.Sprintf(`
resource "aws_efs_file_system" "foo" { resource "aws_efs_file_system" "foo" {
creation_token = "radeksimko" creation_token = "%s"
} }
resource "aws_efs_mount_target" "alpha" { resource "aws_efs_mount_target" "alpha" {
@ -269,4 +276,5 @@ resource "aws_subnet" "beta" {
availability_zone = "us-west-2b" availability_zone = "us-west-2b"
cidr_block = "10.0.2.0/24" cidr_block = "10.0.2.0/24"
} }
` `, ct)
}

View File

@ -6,6 +6,7 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"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"
) )
@ -13,6 +14,8 @@ import (
func TestAccAWSFlowLog_basic(t *testing.T) { func TestAccAWSFlowLog_basic(t *testing.T) {
var flowLog ec2.FlowLog var flowLog ec2.FlowLog
fln := fmt.Sprintf("tf-test-fl-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_flow_log.test_flow_log", IDRefreshName: "aws_flow_log.test_flow_log",
@ -20,7 +23,7 @@ func TestAccAWSFlowLog_basic(t *testing.T) {
CheckDestroy: testAccCheckFlowLogDestroy, CheckDestroy: testAccCheckFlowLogDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccFlowLogConfig_basic, Config: testAccFlowLogConfig_basic(fln),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckFlowLogExists("aws_flow_log.test_flow_log", &flowLog), testAccCheckFlowLogExists("aws_flow_log.test_flow_log", &flowLog),
testAccCheckAWSFlowLogAttributes(&flowLog), testAccCheckAWSFlowLogAttributes(&flowLog),
@ -33,6 +36,8 @@ func TestAccAWSFlowLog_basic(t *testing.T) {
func TestAccAWSFlowLog_subnet(t *testing.T) { func TestAccAWSFlowLog_subnet(t *testing.T) {
var flowLog ec2.FlowLog var flowLog ec2.FlowLog
fln := fmt.Sprintf("tf-test-fl-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_flow_log.test_flow_log_subnet", IDRefreshName: "aws_flow_log.test_flow_log_subnet",
@ -40,7 +45,7 @@ func TestAccAWSFlowLog_subnet(t *testing.T) {
CheckDestroy: testAccCheckFlowLogDestroy, CheckDestroy: testAccCheckFlowLogDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccFlowLogConfig_subnet, Config: testAccFlowLogConfig_subnet(fln),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckFlowLogExists("aws_flow_log.test_flow_log_subnet", &flowLog), testAccCheckFlowLogExists("aws_flow_log.test_flow_log_subnet", &flowLog),
testAccCheckAWSFlowLogAttributes(&flowLog), testAccCheckAWSFlowLogAttributes(&flowLog),
@ -103,7 +108,8 @@ func testAccCheckFlowLogDestroy(s *terraform.State) error {
return nil return nil
} }
var testAccFlowLogConfig_basic = ` func testAccFlowLogConfig_basic(fln string) string {
return fmt.Sprintf(`
resource "aws_vpc" "default" { resource "aws_vpc" "default" {
cidr_block = "10.0.0.0/16" cidr_block = "10.0.0.0/16"
tags { tags {
@ -143,7 +149,7 @@ EOF
} }
resource "aws_cloudwatch_log_group" "foobar" { resource "aws_cloudwatch_log_group" "foobar" {
name = "foo-bar" name = "%s"
} }
resource "aws_flow_log" "test_flow_log" { resource "aws_flow_log" "test_flow_log" {
# log_group_name needs to exist before hand # log_group_name needs to exist before hand
@ -162,9 +168,11 @@ resource "aws_flow_log" "test_flow_log_subnet" {
subnet_id = "${aws_subnet.test_subnet.id}" subnet_id = "${aws_subnet.test_subnet.id}"
traffic_type = "ALL" traffic_type = "ALL"
} }
` `, fln)
}
var testAccFlowLogConfig_subnet = ` func testAccFlowLogConfig_subnet(fln string) string {
return fmt.Sprintf(`
resource "aws_vpc" "default" { resource "aws_vpc" "default" {
cidr_block = "10.0.0.0/16" cidr_block = "10.0.0.0/16"
tags { tags {
@ -203,7 +211,7 @@ resource "aws_iam_role" "test_role" {
EOF EOF
} }
resource "aws_cloudwatch_log_group" "foobar" { resource "aws_cloudwatch_log_group" "foobar" {
name = "foo-bar" name = "%s"
} }
resource "aws_flow_log" "test_flow_log_subnet" { resource "aws_flow_log" "test_flow_log_subnet" {
@ -214,4 +222,5 @@ resource "aws_flow_log" "test_flow_log_subnet" {
subnet_id = "${aws_subnet.test_subnet.id}" subnet_id = "${aws_subnet.test_subnet.id}"
traffic_type = "ALL" traffic_type = "ALL"
} }
` `, fln)
}