From da0d8d58170b4b6240748c667f23be48d02673e5 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Thu, 16 Feb 2017 10:43:41 -0600 Subject: [PATCH 1/2] random some lambda tests --- ...ce_aws_lambda_event_source_mapping_test.go | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/builtin/providers/aws/resource_aws_lambda_event_source_mapping_test.go b/builtin/providers/aws/resource_aws_lambda_event_source_mapping_test.go index ab4f36394..a89b3515c 100644 --- a/builtin/providers/aws/resource_aws_lambda_event_source_mapping_test.go +++ b/builtin/providers/aws/resource_aws_lambda_event_source_mapping_test.go @@ -10,12 +10,14 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "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" ) func TestAccAWSLambdaEventSourceMapping_basic(t *testing.T) { var conf lambda.EventSourceMappingConfiguration + rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -23,14 +25,14 @@ func TestAccAWSLambdaEventSourceMapping_basic(t *testing.T) { CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAWSLambdaEventSourceMappingConfig, + Config: testAccAWSLambdaEventSourceMappingConfig(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists("aws_lambda_event_source_mapping.lambda_event_source_mapping_test", &conf), testAccCheckAWSLambdaEventSourceMappingAttributes(&conf), ), }, resource.TestStep{ - Config: testAccAWSLambdaEventSourceMappingConfigUpdate, + Config: testAccAWSLambdaEventSourceMappingConfigUpdate(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists("aws_lambda_event_source_mapping.lambda_event_source_mapping_test", &conf), resource.TestCheckResourceAttr("aws_lambda_event_source_mapping.lambda_event_source_mapping_test", @@ -53,13 +55,15 @@ func TestAccAWSLambdaEventSourceMapping_basic(t *testing.T) { func TestAccAWSLambdaEventSourceMapping_disappears(t *testing.T) { var conf lambda.EventSourceMappingConfiguration + rInt := acctest.RandInt() + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAWSLambdaEventSourceMappingConfig, + Config: testAccAWSLambdaEventSourceMappingConfig(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckAwsLambdaEventSourceMappingExists("aws_lambda_event_source_mapping.lambda_event_source_mapping_test", &conf), testAccCheckAWSLambdaEventSourceMappingDisappears(&conf), @@ -166,9 +170,10 @@ func testAccCheckAWSLambdaEventSourceMappingAttributes(mapping *lambda.EventSour } } -const testAccAWSLambdaEventSourceMappingConfig = ` +func testAccAWSLambdaEventSourceMappingConfig(rInt int) string { + return fmt.Sprintf(` resource "aws_iam_role" "iam_for_lambda" { - name = "iam_for_lambda" + name = "iam_for_lambda_%d" assume_role_policy = < Date: Thu, 16 Feb 2017 14:20:34 -0600 Subject: [PATCH 2/2] don't send qualifier if it's empty --- builtin/providers/aws/resource_aws_lambda_permission_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_lambda_permission_test.go b/builtin/providers/aws/resource_aws_lambda_permission_test.go index 08be8cbdf..539a3fc89 100644 --- a/builtin/providers/aws/resource_aws_lambda_permission_test.go +++ b/builtin/providers/aws/resource_aws_lambda_permission_test.go @@ -401,7 +401,7 @@ func isLambdaPermissionGone(rs *terraform.ResourceState, conn *lambda.Lambda) er params := &lambda.GetPolicyInput{ FunctionName: aws.String(rs.Primary.Attributes["function_name"]), } - if v, ok := rs.Primary.Attributes["qualifier"]; ok { + if v, ok := rs.Primary.Attributes["qualifier"]; ok && v != "" { params.Qualifier = aws.String(v) } @@ -438,7 +438,7 @@ func lambdaPermissionExists(rs *terraform.ResourceState, conn *lambda.Lambda) (* params := &lambda.GetPolicyInput{ FunctionName: aws.String(rs.Primary.Attributes["function_name"]), } - if v, ok := rs.Primary.Attributes["qualifier"]; ok { + if v, ok := rs.Primary.Attributes["qualifier"]; ok && v != "" { params.Qualifier = aws.String(v) }