add randomness to gateway and efs file system tests

This commit is contained in:
= 2017-03-28 14:56:57 -06:00
parent da7ef1bb76
commit 5662b7e60f
4 changed files with 101 additions and 80 deletions

View File

@ -3,19 +3,20 @@ package aws
import ( import (
"testing" "testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
) )
func TestAccAWSCustomerGateway_importBasic(t *testing.T) { func TestAccAWSCustomerGateway_importBasic(t *testing.T) {
resourceName := "aws_customer_gateway.foo" resourceName := "aws_customer_gateway.foo"
randInt := 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: testAccCheckCustomerGatewayDestroy, CheckDestroy: testAccCheckCustomerGatewayDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccCustomerGatewayConfig, Config: testAccCustomerGatewayConfig(randInt),
}, },
resource.TestStep{ resource.TestStep{

View File

@ -3,11 +3,13 @@ package aws
import ( import (
"testing" "testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
) )
func TestAccAWSEFSFileSystem_importBasic(t *testing.T) { func TestAccAWSEFSFileSystem_importBasic(t *testing.T) {
resourceName := "aws_efs_file_system.foo-with-tags" resourceName := "aws_efs_file_system.foo-with-tags"
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -15,7 +17,7 @@ func TestAccAWSEFSFileSystem_importBasic(t *testing.T) {
CheckDestroy: testAccCheckEfsFileSystemDestroy, CheckDestroy: testAccCheckEfsFileSystemDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccAWSEFSFileSystemConfigWithTags, Config: testAccAWSEFSFileSystemConfigWithTags(rInt),
}, },
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/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"
) )
func TestAccAWSCustomerGateway_basic(t *testing.T) { func TestAccAWSCustomerGateway_basic(t *testing.T) {
var gateway ec2.CustomerGateway var gateway ec2.CustomerGateway
randInt := acctest.RandInt()
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_customer_gateway.foo", IDRefreshName: "aws_customer_gateway.foo",
@ -23,19 +25,19 @@ func TestAccAWSCustomerGateway_basic(t *testing.T) {
CheckDestroy: testAccCheckCustomerGatewayDestroy, CheckDestroy: testAccCheckCustomerGatewayDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
{ {
Config: testAccCustomerGatewayConfig, Config: testAccCustomerGatewayConfig(randInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway), testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway),
), ),
}, },
{ {
Config: testAccCustomerGatewayConfigUpdateTags, Config: testAccCustomerGatewayConfigUpdateTags(randInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway), testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway),
), ),
}, },
{ {
Config: testAccCustomerGatewayConfigForceReplace, Config: testAccCustomerGatewayConfigForceReplace(randInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway), testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway),
), ),
@ -46,6 +48,7 @@ func TestAccAWSCustomerGateway_basic(t *testing.T) {
func TestAccAWSCustomerGateway_similarAlreadyExists(t *testing.T) { func TestAccAWSCustomerGateway_similarAlreadyExists(t *testing.T) {
var gateway ec2.CustomerGateway var gateway ec2.CustomerGateway
randInt := acctest.RandInt()
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_customer_gateway.foo", IDRefreshName: "aws_customer_gateway.foo",
@ -53,13 +56,13 @@ func TestAccAWSCustomerGateway_similarAlreadyExists(t *testing.T) {
CheckDestroy: testAccCheckCustomerGatewayDestroy, CheckDestroy: testAccCheckCustomerGatewayDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
{ {
Config: testAccCustomerGatewayConfig, Config: testAccCustomerGatewayConfig(randInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway), testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway),
), ),
}, },
{ {
Config: testAccCustomerGatewayConfigIdentical, Config: testAccCustomerGatewayConfigIdentical(randInt),
ExpectError: regexp.MustCompile("An existing customer gateway"), ExpectError: regexp.MustCompile("An existing customer gateway"),
}, },
}, },
@ -68,13 +71,14 @@ func TestAccAWSCustomerGateway_similarAlreadyExists(t *testing.T) {
func TestAccAWSCustomerGateway_disappears(t *testing.T) { func TestAccAWSCustomerGateway_disappears(t *testing.T) {
var gateway ec2.CustomerGateway var gateway ec2.CustomerGateway
randInt := 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: testAccCheckCustomerGatewayDestroy, CheckDestroy: testAccCheckCustomerGatewayDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
{ {
Config: testAccCustomerGatewayConfig, Config: testAccCustomerGatewayConfig(randInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway), testAccCheckCustomerGateway("aws_customer_gateway.foo", &gateway),
testAccAWSCustomerGatewayDisappears(&gateway), testAccAWSCustomerGatewayDisappears(&gateway),
@ -190,24 +194,27 @@ func testAccCheckCustomerGateway(gatewayResource string, cgw *ec2.CustomerGatewa
} }
} }
const testAccCustomerGatewayConfig = ` func testAccCustomerGatewayConfig(randInt int) string {
return fmt.Sprintf(`
resource "aws_customer_gateway" "foo" { resource "aws_customer_gateway" "foo" {
bgp_asn = 65000 bgp_asn = 65000
ip_address = "172.0.0.1" ip_address = "172.0.0.1"
type = "ipsec.1" type = "ipsec.1"
tags { tags {
Name = "foo-gateway" Name = "foo-gateway-%d"
} }
} }
` `, randInt)
}
const testAccCustomerGatewayConfigIdentical = ` func testAccCustomerGatewayConfigIdentical(randInt int) string {
return fmt.Sprintf(`
resource "aws_customer_gateway" "foo" { resource "aws_customer_gateway" "foo" {
bgp_asn = 65000 bgp_asn = 65000
ip_address = "172.0.0.1" ip_address = "172.0.0.1"
type = "ipsec.1" type = "ipsec.1"
tags { tags {
Name = "foo-gateway" Name = "foo-gateway-%d"
} }
} }
@ -216,33 +223,38 @@ resource "aws_customer_gateway" "identical" {
ip_address = "172.0.0.1" ip_address = "172.0.0.1"
type = "ipsec.1" type = "ipsec.1"
tags { tags {
Name = "foo-gateway-identical" Name = "foo-gateway-identical-%d"
} }
} }
` `, randInt, randInt)
}
// Add the Another: "tag" tag. // Add the Another: "tag" tag.
const testAccCustomerGatewayConfigUpdateTags = ` func testAccCustomerGatewayConfigUpdateTags(randInt int) string {
return fmt.Sprintf(`
resource "aws_customer_gateway" "foo" { resource "aws_customer_gateway" "foo" {
bgp_asn = 65000 bgp_asn = 65000
ip_address = "172.0.0.1" ip_address = "172.0.0.1"
type = "ipsec.1" type = "ipsec.1"
tags { tags {
Name = "foo-gateway" Name = "foo-gateway-%d"
Another = "tag" Another = "tag-%d"
} }
} }
` `, randInt, randInt)
}
// Change the ip_address. // Change the ip_address.
const testAccCustomerGatewayConfigForceReplace = ` func testAccCustomerGatewayConfigForceReplace(randInt int) string {
return fmt.Sprintf(`
resource "aws_customer_gateway" "foo" { resource "aws_customer_gateway" "foo" {
bgp_asn = 65000 bgp_asn = 65000
ip_address = "172.10.10.1" ip_address = "172.10.10.1"
type = "ipsec.1" type = "ipsec.1"
tags { tags {
Name = "foo-gateway" Name = "foo-gateway-%d"
Another = "tag" Another = "tag-%d"
} }
} }
` `, randInt, randInt)
}

View File

@ -82,6 +82,7 @@ func TestResourceAWSEFSFileSystem_hasEmptyFileSystems(t *testing.T) {
} }
func TestAccAWSEFSFileSystem_basic(t *testing.T) { func TestAccAWSEFSFileSystem_basic(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
@ -104,7 +105,7 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) {
), ),
}, },
{ {
Config: testAccAWSEFSFileSystemConfigWithTags, Config: testAccAWSEFSFileSystemConfigWithTags(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckEfsFileSystem( testAccCheckEfsFileSystem(
"aws_efs_file_system.foo-with-tags", "aws_efs_file_system.foo-with-tags",
@ -116,7 +117,7 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) {
testAccCheckEfsFileSystemTags( testAccCheckEfsFileSystemTags(
"aws_efs_file_system.foo-with-tags", "aws_efs_file_system.foo-with-tags",
map[string]string{ map[string]string{
"Name": "foo-efs", "Name": fmt.Sprintf("foo-efs-%d", rInt),
"Another": "tag", "Another": "tag",
}, },
), ),
@ -143,13 +144,14 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) {
} }
func TestAccAWSEFSFileSystem_pagedTags(t *testing.T) { func TestAccAWSEFSFileSystem_pagedTags(t *testing.T) {
rInt := 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: testAccCheckEfsFileSystemDestroy, CheckDestroy: testAccCheckEfsFileSystemDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
{ {
Config: testAccAWSEFSFileSystemConfigPagedTags, Config: testAccAWSEFSFileSystemConfigPagedTags(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_efs_file_system.foo", "aws_efs_file_system.foo",
@ -312,11 +314,12 @@ resource "aws_efs_file_system" "foo" {
} }
` `
const testAccAWSEFSFileSystemConfigPagedTags = ` func testAccAWSEFSFileSystemConfigPagedTags(rInt int) string {
return fmt.Sprintf(`
resource "aws_efs_file_system" "foo" { resource "aws_efs_file_system" "foo" {
creation_token = "radeksimko" creation_token = "radeksimko"
tags { tags {
Name = "foo-efs" Name = "foo-efs-%d"
Another = "tag" Another = "tag"
Test = "yes" Test = "yes"
User = "root" User = "root"
@ -329,17 +332,20 @@ resource "aws_efs_file_system" "foo" {
Region = "us-west-2" Region = "us-west-2"
} }
} }
` `, rInt)
}
const testAccAWSEFSFileSystemConfigWithTags = ` func testAccAWSEFSFileSystemConfigWithTags(rInt int) string {
return fmt.Sprintf(`
resource "aws_efs_file_system" "foo-with-tags" { resource "aws_efs_file_system" "foo-with-tags" {
creation_token = "yada_yada" creation_token = "yada_yada"
tags { tags {
Name = "foo-efs" Name = "foo-efs-%d"
Another = "tag" Another = "tag"
} }
} }
` `, rInt)
}
const testAccAWSEFSFileSystemConfigWithPerformanceMode = ` const testAccAWSEFSFileSystemConfigWithPerformanceMode = `
resource "aws_efs_file_system" "foo-with-performance-mode" { resource "aws_efs_file_system" "foo-with-performance-mode" {