Skip to content

Commit

Permalink
Merge pull request #15713 from terraform-providers/t-gov-hardarn-lambda
Browse files Browse the repository at this point in the history
tests/provider: Fix hardcoded (Lambda Perm)
  • Loading branch information
YakDriver authored Oct 22, 2020
2 parents 9a9b9de + 3011b12 commit 1573e28
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions aws/resource_aws_lambda_permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestLambdaPermissionUnmarshalling(t *testing.T) {
t.Fatalf("Expected Sid to match (%q != %q)", v.Statement[0].Sid, expectedSid)
}

expectedFunctionName := "arn:aws:lambda:eu-west-1:319201112229:function:myCustomFunction"
expectedFunctionName := "arn:aws:lambda:eu-west-1:319201112229:function:myCustomFunction" // lintignore:AWSAT003,AWSAT005 // unit test
if v.Statement[0].Resource != expectedFunctionName {
t.Fatalf("Expected function name to match (%q != %q)", v.Statement[0].Resource, expectedFunctionName)
}
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestLambdaPermissionUnmarshalling(t *testing.T) {
}

func TestLambdaPermissionGetQualifierFromLambdaAliasOrVersionArn_alias(t *testing.T) {
arnWithAlias := "arn:aws:lambda:us-west-2:187636751137:function:lambda_function_name:testalias"
arnWithAlias := "arn:aws:lambda:us-west-2:187636751137:function:lambda_function_name:testalias" // lintignore:AWSAT003,AWSAT005 // unit test
expectedQualifier := "testalias"
qualifier, err := getQualifierFromLambdaAliasOrVersionArn(arnWithAlias)
if err != nil {
Expand All @@ -71,7 +71,7 @@ func TestLambdaPermissionGetQualifierFromLambdaAliasOrVersionArn_alias(t *testin
}
}
func TestLambdaPermissionGetQualifierFromLambdaAliasOrVersionArn_govcloud(t *testing.T) {
arnWithAlias := "arn:aws-us-gov:lambda:us-gov-west-1:187636751137:function:lambda_function_name:testalias"
arnWithAlias := "arn:aws-us-gov:lambda:us-gov-west-1:187636751137:function:lambda_function_name:testalias" // lintignore:AWSAT003,AWSAT005 // unit test
expectedQualifier := "testalias"
qualifier, err := getQualifierFromLambdaAliasOrVersionArn(arnWithAlias)
if err != nil {
Expand All @@ -83,7 +83,7 @@ func TestLambdaPermissionGetQualifierFromLambdaAliasOrVersionArn_govcloud(t *tes
}

func TestLambdaPermissionGetQualifierFromLambdaAliasOrVersionArn_version(t *testing.T) {
arnWithVersion := "arn:aws:lambda:us-west-2:187636751137:function:lambda_function_name:223"
arnWithVersion := "arn:aws:lambda:us-west-2:187636751137:function:lambda_function_name:223" // lintignore:AWSAT003,AWSAT005 // unit test
expectedQualifier := "223"
qualifier, err := getQualifierFromLambdaAliasOrVersionArn(arnWithVersion)
if err != nil {
Expand All @@ -95,7 +95,7 @@ func TestLambdaPermissionGetQualifierFromLambdaAliasOrVersionArn_version(t *test
}

func TestLambdaPermissionGetQualifierFromLambdaAliasOrVersionArn_invalid(t *testing.T) {
invalidArn := "arn:aws:lambda:us-west-2:187636751137:function:lambda_function_name"
invalidArn := "arn:aws:lambda:us-west-2:187636751137:function:lambda_function_name" // lintignore:AWSAT003,AWSAT005 // unit test
qualifier, err := getQualifierFromLambdaAliasOrVersionArn(invalidArn)
if err == nil {
t.Fatalf("Expected error when getting qualifier")
Expand All @@ -105,7 +105,7 @@ func TestLambdaPermissionGetQualifierFromLambdaAliasOrVersionArn_invalid(t *test
}

// with trailing colon
invalidArn = "arn:aws:lambda:us-west-2:187636751137:function:lambda_function_name:"
invalidArn = "arn:aws:lambda:us-west-2:187636751137:function:lambda_function_name:" // lintignore:AWSAT003,AWSAT005 // unit test
qualifier, err = getQualifierFromLambdaAliasOrVersionArn(invalidArn)
if err == nil {
t.Fatalf("Expected error when getting qualifier")
Expand All @@ -116,7 +116,7 @@ func TestLambdaPermissionGetQualifierFromLambdaAliasOrVersionArn_invalid(t *test
}

func TestLambdaPermissionGetFunctionNameFromLambdaArn_invalid(t *testing.T) {
invalidArn := "arn:aws:lambda:us-west-2:187636751137:function:"
invalidArn := "arn:aws:lambda:us-west-2:187636751137:function:" // lintignore:AWSAT003,AWSAT005 // unit test
fn, err := getFunctionNameFromLambdaArn(invalidArn)
if err == nil {
t.Fatalf("Expected error when parsing invalid ARN (%q)", invalidArn)
Expand All @@ -127,7 +127,7 @@ func TestLambdaPermissionGetFunctionNameFromLambdaArn_invalid(t *testing.T) {
}

func TestLambdaPermissionGetFunctionNameFromLambdaArn_valid(t *testing.T) {
validArn := "arn:aws:lambda:us-west-2:187636751137:function:lambda_function_name"
validArn := "arn:aws:lambda:us-west-2:187636751137:function:lambda_function_name" // lintignore:AWSAT003,AWSAT005 // unit test
fn, err := getFunctionNameFromLambdaArn(validArn)
if err != nil {
t.Fatalf("Expected no error (%q): %q", validArn, err)
Expand All @@ -139,7 +139,7 @@ func TestLambdaPermissionGetFunctionNameFromLambdaArn_valid(t *testing.T) {
}

// With qualifier
validArn = "arn:aws:lambda:us-west-2:187636751137:function:lambda_function_name:12"
validArn = "arn:aws:lambda:us-west-2:187636751137:function:lambda_function_name:12" // lintignore:AWSAT003,AWSAT005 // unit test
fn, err = getFunctionNameFromLambdaArn(validArn)
if err != nil {
t.Fatalf("Expected no error (%q): %q", validArn, err)
Expand All @@ -152,7 +152,7 @@ func TestLambdaPermissionGetFunctionNameFromLambdaArn_valid(t *testing.T) {
}

func TestLambdaPermissionGetFunctionNameFromGovCloudLambdaArn(t *testing.T) {
validArn := "arn:aws-us-gov:lambda:us-gov-west-1:187636751137:function:lambda_function_name"
validArn := "arn:aws-us-gov:lambda:us-gov-west-1:187636751137:function:lambda_function_name" // lintignore:AWSAT003,AWSAT005 // unit test
fn, err := getFunctionNameFromLambdaArn(validArn)
if err != nil {
t.Fatalf("Expected no error (%q): %q", validArn, err)
Expand Down Expand Up @@ -884,6 +884,7 @@ EOF
}

func testAccAWSLambdaPermissionConfig_withQualifier(aliasName, funcName, roleName string) string {
// lintignore:AWSAT003,AWSAT005 // ARN, region not actually used
return fmt.Sprintf(`
resource "aws_lambda_permission" "with_qualifier" {
statement_id = "AllowExecutionWithQualifier"
Expand Down Expand Up @@ -1128,6 +1129,7 @@ EOF
`, funcName, roleName)
}

// lintignore:AWSAT003,AWSAT005 // unit test
var testLambdaPolicy = []byte(`{
"Version": "2012-10-17",
"Statement": [
Expand Down

0 comments on commit 1573e28

Please sign in to comment.