provider/aws: randomiz names in TestAccAWSCloudwatchLogSubscriptionFilter_basic

This commit is contained in:
clint shryock 2016-06-06 10:25:02 -05:00
parent a1021f32e1
commit 3044cc5c38

View File

@ -6,6 +6,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
@ -13,16 +14,18 @@ import (
func TestAccAWSCloudwatchLogSubscriptionFilter_basic(t *testing.T) {
var conf lambda.GetFunctionOutput
rstring := acctest.RandString(5)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudwatchLogSubscriptionFilterDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSCloudwatchLogSubscriptionFilterConfig,
Config: testAccAWSCloudwatchLogSubscriptionFilterConfig(rstring),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsCloudwatchLogSubscriptionFilterExists("aws_cloudwatch_log_subscription_filter.test_lambdafunction_logfilter", &conf),
testAccCheckAWSCloudwatchLogSubscriptionFilterAttributes(&conf),
testAccCheckAwsCloudwatchLogSubscriptionFilterExists("aws_cloudwatch_log_subscription_filter.test_lambdafunction_logfilter", &conf, rstring),
testAccCheckAWSCloudwatchLogSubscriptionFilterAttributes(&conf, rstring),
),
},
},
@ -51,7 +54,7 @@ func testAccCheckCloudwatchLogSubscriptionFilterDestroy(s *terraform.State) erro
}
func testAccCheckAwsCloudwatchLogSubscriptionFilterExists(n string, function *lambda.GetFunctionOutput) resource.TestCheckFunc {
func testAccCheckAwsCloudwatchLogSubscriptionFilterExists(n string, function *lambda.GetFunctionOutput, rstring string) resource.TestCheckFunc {
// Wait for IAM role
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
@ -66,7 +69,7 @@ func testAccCheckAwsCloudwatchLogSubscriptionFilterExists(n string, function *la
conn := testAccProvider.Meta().(*AWSClient).lambdaconn
params := &lambda.GetFunctionInput{
FunctionName: aws.String("example_lambda_name"),
FunctionName: aws.String("example_lambda_name_" + rstring),
}
getFunction, err := conn.GetFunction(params)
@ -80,10 +83,10 @@ func testAccCheckAwsCloudwatchLogSubscriptionFilterExists(n string, function *la
}
}
func testAccCheckAWSCloudwatchLogSubscriptionFilterAttributes(function *lambda.GetFunctionOutput) resource.TestCheckFunc {
func testAccCheckAWSCloudwatchLogSubscriptionFilterAttributes(function *lambda.GetFunctionOutput, rstring string) resource.TestCheckFunc {
return func(s *terraform.State) error {
c := function.Configuration
const expectedName = "example_lambda_name"
expectedName := fmt.Sprintf("example_lambda_name_%s", rstring)
if *c.FunctionName != expectedName {
return fmt.Errorf("Expected function name %s, got %s", expectedName, *c.FunctionName)
}
@ -96,7 +99,8 @@ func testAccCheckAWSCloudwatchLogSubscriptionFilterAttributes(function *lambda.G
}
}
const testAccAWSCloudwatchLogSubscriptionFilterConfig = `
func testAccAWSCloudwatchLogSubscriptionFilterConfig(rstring string) string {
return fmt.Sprintf(`
resource "aws_cloudwatch_log_subscription_filter" "test_lambdafunction_logfilter" {
name = "test_lambdafunction_logfilter"
log_group_name = "example_lambda_name"
@ -106,7 +110,7 @@ resource "aws_cloudwatch_log_subscription_filter" "test_lambdafunction_logfilter
resource "aws_lambda_function" "test_lambdafunction" {
filename = "test-fixtures/lambdatest.zip"
function_name = "example_lambda_name"
function_name = "example_lambda_name_%s"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.handler"
}
@ -124,7 +128,7 @@ resource "aws_lambda_permission" "allow_cloudwatch_logs" {
}
resource "aws_iam_role" "iam_for_lambda" {
name = "test_lambdafuntion_iam_role"
name = "test_lambdafuntion_iam_role_%s"
assume_role_policy = <<EOF
{
@ -165,4 +169,5 @@ resource "aws_iam_role_policy" "test_lambdafunction_iam_policy" {
}
EOF
}
`
`, rstring, rstring)
}