Skip to content

Commit 79e8680

Browse files
author
Sid Madipalli
committed
Added translator transform templated tests
1 parent 6a37502 commit 79e8680

9 files changed

+327
-0
lines changed

tests/model/test_sam_resources.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,8 @@ def test_role_get_att_no_execution_role(self):
851851
lambda_function = next(r for r in cfn_resources if r.resource_type == "AWS::Lambda::Function")
852852

853853
self.assertEqual(lambda_function.Role, role_get_att)
854+
855+
854856
class TestSamCapacityProvider(TestCase):
855857
"""Tests for SamCapacityProvider"""
856858

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Resources:
2+
MinimalFunction:
3+
Type: AWS::Serverless::Function
4+
Properties:
5+
CodeUri: s3://sam-demo-bucket/hello.zip
6+
Handler: hello.handler
7+
Runtime: python3.10
8+
Role: 2
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Parameters:
2+
iamRoleArn:
3+
Type: String
4+
Description: The ARN of an IAM role to use as this function's execution role.
5+
If a role isn't specified, one is created for you with a logical ID of <function-logical-id>Role.
6+
7+
Conditions:
8+
RoleExists: !Not [!Equals ['', !Ref iamRoleArn]]
9+
10+
Resources:
11+
MinimalFunction:
12+
Type: AWS::Serverless::Function
13+
Properties:
14+
CodeUri: s3://sam-demo-bucket/hello.zip
15+
Handler: hello.handler
16+
Runtime: python3.10
17+
Role: !If
18+
- RoleExists
19+
- !Ref "iamRoleArn"
20+
- !Ref "AWS::NoValue"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"_autoGeneratedBreakdownErrorMessage": [
3+
"Invalid Serverless Application Specification document. ",
4+
"Number of errors found: 1. ",
5+
"Resource with id [MinimalFunction] is invalid. ",
6+
"Property 'Role' should be a string."
7+
],
8+
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MinimalFunction] is invalid. Property 'Role' should be a string.",
9+
"errors": [
10+
{
11+
"errorMessage": "Resource with id [MinimalFunction] is invalid. Property 'Role' should be a string."
12+
}
13+
]
14+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"Conditions": {
3+
"RoleExists": {
4+
"Fn::Not": [
5+
{
6+
"Fn::Equals": [
7+
"",
8+
{
9+
"Ref": "iamRoleArn"
10+
}
11+
]
12+
}
13+
]
14+
}
15+
},
16+
"Parameters": {
17+
"iamRoleArn": {
18+
"Description": "The ARN of an IAM role to use as this function's execution role. If a role isn't specified, one is created for you with a logical ID of <function-logical-id>Role.",
19+
"Type": "String"
20+
}
21+
},
22+
"Resources": {
23+
"MinimalFunction": {
24+
"Properties": {
25+
"Code": {
26+
"S3Bucket": "sam-demo-bucket",
27+
"S3Key": "hello.zip"
28+
},
29+
"Handler": "hello.handler",
30+
"Role": {
31+
"Fn::If": [
32+
"RoleExists",
33+
{
34+
"Ref": "iamRoleArn"
35+
},
36+
{
37+
"Fn::GetAtt": [
38+
"MinimalFunctionRole",
39+
"Arn"
40+
]
41+
}
42+
]
43+
},
44+
"Runtime": "python3.10",
45+
"Tags": [
46+
{
47+
"Key": "lambda:createdBy",
48+
"Value": "SAM"
49+
}
50+
]
51+
},
52+
"Type": "AWS::Lambda::Function"
53+
},
54+
"MinimalFunctionRole": {
55+
"Properties": {
56+
"AssumeRolePolicyDocument": {
57+
"Statement": [
58+
{
59+
"Action": [
60+
"sts:AssumeRole"
61+
],
62+
"Effect": "Allow",
63+
"Principal": {
64+
"Service": [
65+
"lambda.amazonaws.com"
66+
]
67+
}
68+
}
69+
],
70+
"Version": "2012-10-17"
71+
},
72+
"ManagedPolicyArns": [
73+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
74+
],
75+
"Tags": [
76+
{
77+
"Key": "lambda:createdBy",
78+
"Value": "SAM"
79+
}
80+
]
81+
},
82+
"Type": "AWS::IAM::Role"
83+
}
84+
}
85+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"_autoGeneratedBreakdownErrorMessage": [
3+
"Invalid Serverless Application Specification document. ",
4+
"Number of errors found: 1. ",
5+
"Resource with id [MinimalFunction] is invalid. ",
6+
"Property 'Role' should be a string."
7+
],
8+
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MinimalFunction] is invalid. Property 'Role' should be a string.",
9+
"errors": [
10+
{
11+
"errorMessage": "Resource with id [MinimalFunction] is invalid. Property 'Role' should be a string."
12+
}
13+
]
14+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"Conditions": {
3+
"RoleExists": {
4+
"Fn::Not": [
5+
{
6+
"Fn::Equals": [
7+
"",
8+
{
9+
"Ref": "iamRoleArn"
10+
}
11+
]
12+
}
13+
]
14+
}
15+
},
16+
"Parameters": {
17+
"iamRoleArn": {
18+
"Description": "The ARN of an IAM role to use as this function's execution role. If a role isn't specified, one is created for you with a logical ID of <function-logical-id>Role.",
19+
"Type": "String"
20+
}
21+
},
22+
"Resources": {
23+
"MinimalFunction": {
24+
"Properties": {
25+
"Code": {
26+
"S3Bucket": "sam-demo-bucket",
27+
"S3Key": "hello.zip"
28+
},
29+
"Handler": "hello.handler",
30+
"Role": {
31+
"Fn::If": [
32+
"RoleExists",
33+
{
34+
"Ref": "iamRoleArn"
35+
},
36+
{
37+
"Fn::GetAtt": [
38+
"MinimalFunctionRole",
39+
"Arn"
40+
]
41+
}
42+
]
43+
},
44+
"Runtime": "python3.10",
45+
"Tags": [
46+
{
47+
"Key": "lambda:createdBy",
48+
"Value": "SAM"
49+
}
50+
]
51+
},
52+
"Type": "AWS::Lambda::Function"
53+
},
54+
"MinimalFunctionRole": {
55+
"Properties": {
56+
"AssumeRolePolicyDocument": {
57+
"Statement": [
58+
{
59+
"Action": [
60+
"sts:AssumeRole"
61+
],
62+
"Effect": "Allow",
63+
"Principal": {
64+
"Service": [
65+
"lambda.amazonaws.com"
66+
]
67+
}
68+
}
69+
],
70+
"Version": "2012-10-17"
71+
},
72+
"ManagedPolicyArns": [
73+
"arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
74+
],
75+
"Tags": [
76+
{
77+
"Key": "lambda:createdBy",
78+
"Value": "SAM"
79+
}
80+
]
81+
},
82+
"Type": "AWS::IAM::Role"
83+
}
84+
}
85+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"_autoGeneratedBreakdownErrorMessage": [
3+
"Invalid Serverless Application Specification document. ",
4+
"Number of errors found: 1. ",
5+
"Resource with id [MinimalFunction] is invalid. ",
6+
"Property 'Role' should be a string."
7+
],
8+
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MinimalFunction] is invalid. Property 'Role' should be a string.",
9+
"errors": [
10+
{
11+
"errorMessage": "Resource with id [MinimalFunction] is invalid. Property 'Role' should be a string."
12+
}
13+
]
14+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"Conditions": {
3+
"RoleExists": {
4+
"Fn::Not": [
5+
{
6+
"Fn::Equals": [
7+
"",
8+
{
9+
"Ref": "iamRoleArn"
10+
}
11+
]
12+
}
13+
]
14+
}
15+
},
16+
"Parameters": {
17+
"iamRoleArn": {
18+
"Description": "The ARN of an IAM role to use as this function's execution role. If a role isn't specified, one is created for you with a logical ID of <function-logical-id>Role.",
19+
"Type": "String"
20+
}
21+
},
22+
"Resources": {
23+
"MinimalFunction": {
24+
"Properties": {
25+
"Code": {
26+
"S3Bucket": "sam-demo-bucket",
27+
"S3Key": "hello.zip"
28+
},
29+
"Handler": "hello.handler",
30+
"Role": {
31+
"Fn::If": [
32+
"RoleExists",
33+
{
34+
"Ref": "iamRoleArn"
35+
},
36+
{
37+
"Fn::GetAtt": [
38+
"MinimalFunctionRole",
39+
"Arn"
40+
]
41+
}
42+
]
43+
},
44+
"Runtime": "python3.10",
45+
"Tags": [
46+
{
47+
"Key": "lambda:createdBy",
48+
"Value": "SAM"
49+
}
50+
]
51+
},
52+
"Type": "AWS::Lambda::Function"
53+
},
54+
"MinimalFunctionRole": {
55+
"Properties": {
56+
"AssumeRolePolicyDocument": {
57+
"Statement": [
58+
{
59+
"Action": [
60+
"sts:AssumeRole"
61+
],
62+
"Effect": "Allow",
63+
"Principal": {
64+
"Service": [
65+
"lambda.amazonaws.com"
66+
]
67+
}
68+
}
69+
],
70+
"Version": "2012-10-17"
71+
},
72+
"ManagedPolicyArns": [
73+
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
74+
],
75+
"Tags": [
76+
{
77+
"Key": "lambda:createdBy",
78+
"Value": "SAM"
79+
}
80+
]
81+
},
82+
"Type": "AWS::IAM::Role"
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)