provider/aws: Ranomize LB names so tests can run at the same time

This commit is contained in:
clint shryock 2016-05-26 03:37:54 -05:00
parent a8de40090a
commit 6f04c36a1a
3 changed files with 38 additions and 26 deletions

View File

@ -8,18 +8,20 @@ import (
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccAWSAppCookieStickinessPolicy_basic(t *testing.T) {
lbName := fmt.Sprintf("tf-test-lb-%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAppCookieStickinessPolicyDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAppCookieStickinessPolicyConfig,
Config: testAccAppCookieStickinessPolicyConfig(lbName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppCookieStickinessPolicy(
"aws_elb.lb",
@ -28,7 +30,7 @@ func TestAccAWSAppCookieStickinessPolicy_basic(t *testing.T) {
),
},
resource.TestStep{
Config: testAccAppCookieStickinessPolicyConfigUpdate,
Config: testAccAppCookieStickinessPolicyConfigUpdate(lbName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppCookieStickinessPolicy(
"aws_elb.lb",
@ -100,9 +102,10 @@ func testAccCheckAppCookieStickinessPolicy(elbResource string, policyResource st
}
}
const testAccAppCookieStickinessPolicyConfig = `
func testAccAppCookieStickinessPolicyConfig(rName string) string {
return fmt.Sprintf(`
resource "aws_elb" "lb" {
name = "test-lb"
name = "%s"
availability_zones = ["us-west-2a"]
listener {
instance_port = 8000
@ -117,13 +120,14 @@ resource "aws_app_cookie_stickiness_policy" "foo" {
load_balancer = "${aws_elb.lb.id}"
lb_port = 80
cookie_name = "MyAppCookie"
}`, rName)
}
`
// Change the cookie_name to "MyOtherAppCookie".
const testAccAppCookieStickinessPolicyConfigUpdate = `
func testAccAppCookieStickinessPolicyConfigUpdate(rName string) string {
return fmt.Sprintf(`
resource "aws_elb" "lb" {
name = "test-lb"
name = "%s"
availability_zones = ["us-west-2a"]
listener {
instance_port = 8000
@ -138,5 +142,5 @@ resource "aws_app_cookie_stickiness_policy" "foo" {
load_balancer = "${aws_elb.lb.id}"
lb_port = 80
cookie_name = "MyOtherAppCookie"
}`, rName)
}
`

View File

@ -8,18 +8,20 @@ import (
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccAWSLBCookieStickinessPolicy_basic(t *testing.T) {
lbName := fmt.Sprintf("tf-test-lb-%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLBCookieStickinessPolicyDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccLBCookieStickinessPolicyConfig,
Config: testAccLBCookieStickinessPolicyConfig(lbName),
Check: resource.ComposeTestCheckFunc(
testAccCheckLBCookieStickinessPolicy(
"aws_elb.lb",
@ -28,7 +30,7 @@ func TestAccAWSLBCookieStickinessPolicy_basic(t *testing.T) {
),
},
resource.TestStep{
Config: testAccLBCookieStickinessPolicyConfigUpdate,
Config: testAccLBCookieStickinessPolicyConfigUpdate(lbName),
Check: resource.ComposeTestCheckFunc(
testAccCheckLBCookieStickinessPolicy(
"aws_elb.lb",
@ -100,9 +102,10 @@ func testAccCheckLBCookieStickinessPolicy(elbResource string, policyResource str
}
}
const testAccLBCookieStickinessPolicyConfig = `
func testAccLBCookieStickinessPolicyConfig(rName string) string {
return fmt.Sprintf(`
resource "aws_elb" "lb" {
name = "test-lb"
name = "%s"
availability_zones = ["us-west-2a"]
listener {
instance_port = 8000
@ -116,13 +119,14 @@ resource "aws_lb_cookie_stickiness_policy" "foo" {
name = "foo-policy"
load_balancer = "${aws_elb.lb.id}"
lb_port = 80
}`, rName)
}
`
// Sets the cookie_expiration_period to 300s.
const testAccLBCookieStickinessPolicyConfigUpdate = `
func testAccLBCookieStickinessPolicyConfigUpdate(rName string) string {
return fmt.Sprintf(`
resource "aws_elb" "lb" {
name = "test-lb"
name = "%s"
availability_zones = ["us-west-2a"]
listener {
instance_port = 8000
@ -137,5 +141,5 @@ resource "aws_lb_cookie_stickiness_policy" "foo" {
load_balancer = "${aws_elb.lb.id}"
lb_port = 80
cookie_expiration_period = 300
}`, rName)
}
`

View File

@ -6,21 +6,23 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccAWSProxyProtocolPolicy_basic(t *testing.T) {
lbName := fmt.Sprintf("tf-test-lb-%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckProxyProtocolPolicyDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccProxyProtocolPolicyConfig,
Config: testAccProxyProtocolPolicyConfig(lbName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"aws_proxy_protocol_policy.smtp", "load_balancer", "test-lb"),
"aws_proxy_protocol_policy.smtp", "load_balancer", lbName),
resource.TestCheckResourceAttr(
"aws_proxy_protocol_policy.smtp", "instance_ports.#", "1"),
resource.TestCheckResourceAttr(
@ -28,10 +30,10 @@ func TestAccAWSProxyProtocolPolicy_basic(t *testing.T) {
),
},
resource.TestStep{
Config: testAccProxyProtocolPolicyConfigUpdate,
Config: testAccProxyProtocolPolicyConfigUpdate(lbName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"aws_proxy_protocol_policy.smtp", "load_balancer", "test-lb"),
"aws_proxy_protocol_policy.smtp", "load_balancer", lbName),
resource.TestCheckResourceAttr(
"aws_proxy_protocol_policy.smtp", "instance_ports.#", "2"),
resource.TestCheckResourceAttr(
@ -70,9 +72,10 @@ func testAccCheckProxyProtocolPolicyDestroy(s *terraform.State) error {
return nil
}
const testAccProxyProtocolPolicyConfig = `
func testAccProxyProtocolPolicyConfig(rName string) string {
return fmt.Sprintf(`
resource "aws_elb" "lb" {
name = "test-lb"
name = "%s"
availability_zones = ["us-west-2a"]
listener {
@ -93,12 +96,13 @@ resource "aws_elb" "lb" {
resource "aws_proxy_protocol_policy" "smtp" {
load_balancer = "${aws_elb.lb.name}"
instance_ports = ["25"]
}`, rName)
}
`
const testAccProxyProtocolPolicyConfigUpdate = `
func testAccProxyProtocolPolicyConfigUpdate(rName string) string {
return fmt.Sprintf(`
resource "aws_elb" "lb" {
name = "test-lb"
name = "%s"
availability_zones = ["us-west-2a"]
listener {
@ -119,5 +123,5 @@ resource "aws_elb" "lb" {
resource "aws_proxy_protocol_policy" "smtp" {
load_balancer = "${aws_elb.lb.name}"
instance_ports = ["25", "587"]
}`, rName)
}
`