Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-added tests #5049

Merged
merged 2 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aws/resource_aws_lambda_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ func expandLambdaAliasRoutingConfiguration(l []interface{}) *lambda.AliasRouting

m := l[0].(map[string]interface{})

if _, ok := m["additional_version_weights"]; ok {
aliasRoutingConfiguration.AdditionalVersionWeights = expandFloat64Map(m)
if v, ok := m["additional_version_weights"]; ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this! 💯

aliasRoutingConfiguration.AdditionalVersionWeights = expandFloat64Map(v.(map[string]interface{}))
}

return aliasRoutingConfiguration
Expand Down
49 changes: 49 additions & 0 deletions aws/resource_aws_lambda_alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestAccAWSLambdaAlias_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaAliasExists("aws_lambda_alias.lambda_alias_test", &conf),
testAccCheckAwsLambdaAttributes(&conf),
testAccCheckAwsLambdaAliasRoutingConfigDoesNotExist(&conf),
resource.TestMatchResourceAttr("aws_lambda_alias.lambda_alias_test", "arn",
regexp.MustCompile(`^arn:aws:lambda:[a-z]+-[a-z]+-[0-9]+:\d{12}:function:`+funcName+`:`+aliasName+`$`)),
),
Expand Down Expand Up @@ -78,6 +79,54 @@ func TestAccAWSLambdaAlias_nameupdate(t *testing.T) {
})
}

func TestAccAWSLambdaAlias_routingconfig(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This acceptance test is currently failing for me:

make testacc TEST=./aws TESTARGS='-run=TestAccAWSLambdaAlias_routingconfig'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSLambdaAlias_routingconfig -timeout 120m
=== RUN   TestAccAWSLambdaAlias_routingconfig
--- FAIL: TestAccAWSLambdaAlias_routingconfig (86.12s)
	testing.go:518: Step 0 error: Error applying: 1 error(s) occurred:

		* aws_lambda_alias.lambda_alias_test: 1 error(s) occurred:

		* aws_lambda_alias.lambda_alias_test: Error creating Lambda alias: ResourceNotFoundException: Function not found: arn:aws:lambda:us-west-2:187416307283:function:tf_acc_lambda_func_alias_basic_vmhu4b4h:2
			status code: 404, request id: 8e743c6f-7e17-11e8-81bb-0f6cecc9e91a
FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	86.161s

Its complaining because version 2 of the Lambda function (newly created in the test) does not exist. I'm not sure its possible to create this configuration without at least two versions of the Lambda function existing already. When trying to set the routing configuration in the existing test configuration to:

  routing_config   = {
    additional_version_weights = {
      "1" = 0.5
    }
  }

I get:

		* aws_lambda_alias.lambda_alias_test: Error creating Lambda alias: InvalidParameterValueException: Invalid function version 1. Function version 1 is already included in routing configuration.
			status code: 400, request id: 6f7ccbcf-7e16-11e8-b729-25d25f4dd472

Copy link
Contributor Author

@eggsbenjamin eggsbenjamin Jul 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bflad my poor merge resulted in this test getting lost sorry.

It creates multiple versions in order for traffic shifting to be possible and tests that the routing config can be added an removed. Acceptance tests passing.

=== RUN   TestAccAWSLambdaAlias_routingconfig
--- PASS: TestAccAWSLambdaAlias_routingconfig (74.10s)
PASS
ok      github.com/eggsbenjamin/terraform-provider-aws/aws      74.131s

var conf lambda.AliasConfiguration

rString := acctest.RandString(8)
roleName := fmt.Sprintf("tf_acc_role_lambda_alias_basic_%s", rString)
policyName := fmt.Sprintf("tf_acc_policy_lambda_alias_basic_%s", rString)
attachmentName := fmt.Sprintf("tf_acc_attachment_%s", rString)
funcName := fmt.Sprintf("tf_acc_lambda_func_alias_basic_%s", rString)
aliasName := fmt.Sprintf("tf_acc_lambda_alias_basic_%s", rString)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsLambdaAliasDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsLambdaAliasConfig(roleName, policyName, attachmentName, funcName, aliasName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaAliasExists("aws_lambda_alias.lambda_alias_test", &conf),
testAccCheckAwsLambdaAttributes(&conf),
resource.TestMatchResourceAttr("aws_lambda_alias.lambda_alias_test", "arn",
regexp.MustCompile(`^arn:aws:lambda:[a-z]+-[a-z]+-[0-9]+:\d{12}:function:`+funcName+`:`+aliasName+`$`)),
),
},
{
Config: testAccAwsLambdaAliasConfigWithRoutingConfig(roleName, policyName, attachmentName, funcName, aliasName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaAliasExists("aws_lambda_alias.lambda_alias_test", &conf),
testAccCheckAwsLambdaAttributes(&conf),
testAccCheckAwsLambdaAliasRoutingConfigExists(&conf),
resource.TestMatchResourceAttr("aws_lambda_alias.lambda_alias_test", "arn",
regexp.MustCompile(`^arn:aws:lambda:[a-z]+-[a-z]+-[0-9]+:\d{12}:function:`+funcName+`:`+aliasName+`$`)),
),
},
{
Config: testAccAwsLambdaAliasConfig(roleName, policyName, attachmentName, funcName, aliasName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaAliasExists("aws_lambda_alias.lambda_alias_test", &conf),
testAccCheckAwsLambdaAttributes(&conf),
testAccCheckAwsLambdaAliasRoutingConfigDoesNotExist(&conf),
resource.TestMatchResourceAttr("aws_lambda_alias.lambda_alias_test", "arn",
regexp.MustCompile(`^arn:aws:lambda:[a-z]+-[a-z]+-[0-9]+:\d{12}:function:`+funcName+`:`+aliasName+`$`)),
),
},
},
})
}

func testAccCheckAwsLambdaAliasDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).lambdaconn

Expand Down