more aws acc test fixes (#12568)

* provider/aws: fix TestAccAWSAutoScalingGroup_ALB_TargetGroups_ELBCapacity

* provider/aws: Randomize to fix TestAccDataSourceAwsVpc_basic
This commit is contained in:
Clint 2017-03-09 16:01:18 -06:00 committed by GitHub
parent 3fdeacdca7
commit d24c761bbb
2 changed files with 35 additions and 20 deletions

View File

@ -2,24 +2,28 @@ package aws
import (
"fmt"
"math/rand"
"testing"
"time"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccDataSourceAwsVpc_basic(t *testing.T) {
rand.Seed(time.Now().UTC().UnixNano())
cidr := fmt.Sprintf("172.%d.0.0/16", rand.Intn(16))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsVpcConfig,
Config: testAccDataSourceAwsVpcConfig(cidr),
Check: resource.ComposeTestCheckFunc(
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_id"),
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_cidr"),
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_tag"),
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_filter"),
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_id", cidr),
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_cidr", cidr),
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_tag", cidr),
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_filter", cidr),
),
},
},
@ -27,14 +31,16 @@ func TestAccDataSourceAwsVpc_basic(t *testing.T) {
}
func TestAccDataSourceAwsVpc_ipv6Associated(t *testing.T) {
rand.Seed(time.Now().UTC().UnixNano())
cidr := fmt.Sprintf("172.%d.0.0/16", rand.Intn(16))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsVpcConfigIpv6,
Config: testAccDataSourceAwsVpcConfigIpv6(cidr),
Check: resource.ComposeTestCheckFunc(
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_id"),
testAccDataSourceAwsVpcCheck("data.aws_vpc.by_id", cidr),
resource.TestCheckResourceAttrSet(
"data.aws_vpc.by_id", "ipv6_association_id"),
resource.TestCheckResourceAttrSet(
@ -45,7 +51,7 @@ func TestAccDataSourceAwsVpc_ipv6Associated(t *testing.T) {
})
}
func testAccDataSourceAwsVpcCheck(name string) resource.TestCheckFunc {
func testAccDataSourceAwsVpcCheck(name, cidr string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
@ -67,8 +73,8 @@ func testAccDataSourceAwsVpcCheck(name string) resource.TestCheckFunc {
)
}
if attr["cidr_block"] != "172.16.0.0/16" {
return fmt.Errorf("bad cidr_block %s", attr["cidr_block"])
if attr["cidr_block"] != cidr {
return fmt.Errorf("bad cidr_block %s, expected: %s", attr["cidr_block"], cidr)
}
if attr["tags.Name"] != "terraform-testacc-vpc-data-source" {
return fmt.Errorf("bad Name tag %s", attr["tags.Name"])
@ -78,13 +84,14 @@ func testAccDataSourceAwsVpcCheck(name string) resource.TestCheckFunc {
}
}
const testAccDataSourceAwsVpcConfigIpv6 = `
func testAccDataSourceAwsVpcConfigIpv6(cidr string) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "test" {
cidr_block = "172.16.0.0/16"
cidr_block = "%s"
assign_generated_ipv6_cidr_block = true
tags {
@ -94,16 +101,17 @@ resource "aws_vpc" "test" {
data "aws_vpc" "by_id" {
id = "${aws_vpc.test.id}"
}`, cidr)
}
`
const testAccDataSourceAwsVpcConfig = `
func testAccDataSourceAwsVpcConfig(cidr string) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "test" {
cidr_block = "172.16.0.0/16"
cidr_block = "%s"
tags {
Name = "terraform-testacc-vpc-data-source"
@ -129,5 +137,5 @@ data "aws_vpc" "by_filter" {
name = "cidr"
values = ["${aws_vpc.test.cidr_block}"]
}
}`, cidr)
}
`

View File

@ -472,13 +472,15 @@ func TestAccAWSAutoScalingGroup_ALB_TargetGroups_ELBCapacity(t *testing.T) {
var group autoscaling.Group
var tg elbv2.TargetGroup
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_ELBCapacity,
Config: testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_ELBCapacity(rInt),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &tg),
@ -1386,7 +1388,8 @@ resource "aws_autoscaling_group" "bar" {
`, name)
}
const testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_ELBCapacity = `
func testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_ELBCapacity(rInt int) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
}
@ -1420,7 +1423,7 @@ resource "aws_alb_listener" "test_listener" {
}
resource "aws_alb_target_group" "test" {
name = "tf-example-alb-tg"
name = "tf-alb-test-%d"
port = 80
protocol = "HTTP"
vpc_id = "${aws_vpc.default.id}"
@ -1431,6 +1434,10 @@ resource "aws_alb_target_group" "test" {
timeout = "2"
interval = "5"
}
tags {
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_ELBCapacity"
}
}
resource "aws_subnet" "main" {
@ -1522,8 +1529,8 @@ resource "aws_autoscaling_group" "bar" {
force_delete = true
termination_policies = ["OldestInstance"]
launch_configuration = "${aws_launch_configuration.foobar.name}"
}`, rInt)
}
`
func testAccAWSAutoScalingGroupConfigWithSuspendedProcesses(name string) string {
return fmt.Sprintf(`