Skip to content

Commit

Permalink
chore(tests): Added a test for JSON resource tags (awslabs#248)
Browse files Browse the repository at this point in the history
see issue awslabs#223
  • Loading branch information
PaulMaddox authored Nov 30, 2019
1 parent aafcbdd commit 387676f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
27 changes: 27 additions & 0 deletions goformation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,33 @@ var _ = Describe("Goformation", func() {

})

Context("with a JSON template that contains a resource with tags", func() {

template, err := goformation.Open("test/json/resource-with-tags.json")
It("should successfully validate the template", func() {
Expect(err).To(BeNil())
Expect(template).ShouldNot(BeNil())
})

resources := template.GetAllAutoScalingAutoScalingGroupResources()
It("should have exactly one resource", func() {
Expect(resources).To(HaveLen(1))
Expect(resources).To(HaveKey("EcsClusterDefaultAutoScalingGroupASGC1A785DB"))
})

asg := resources["EcsClusterDefaultAutoScalingGroupASGC1A785DB"]
It("should have exactly one tag defined", func() {
Expect(asg.Tags).To(HaveLen(1))
})

It("should have the correct tag properties set", func() {
Expect(asg.Tags[0].PropagateAtLaunch).To(Equal(true))
Expect(asg.Tags[0].Key).To(Equal("Name"))
Expect(asg.Tags[0].Value).To(Equal("aws-ecs-integ-ecs/EcsCluster/DefaultAutoScalingGroup"))
})

})

Context("with a Custom Resource template", func() {

template, err := goformation.Open("test/yaml/custom-resource.yaml")
Expand Down
32 changes: 32 additions & 0 deletions test/json/resource-with-tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Valid CloudFormation template",
"Resources": {
"EcsClusterDefaultAutoScalingGroupASGC1A785DB": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"MaxSize": "1",
"MinSize": "1",
"DesiredCapacity": "1",
"LaunchConfigurationName": {
"Ref": "EcsClusterDefaultAutoScalingGroupLaunchConfigB7E376C1"
},
"Tags": [
{
"Key": "Name",
"PropagateAtLaunch": true,
"Value": "aws-ecs-integ-ecs/EcsCluster/DefaultAutoScalingGroup"
}
],
"VPCZoneIdentifier": [
{
"Ref": "VpcPrivateSubnet1Subnet536B997A"
},
{
"Ref": "VpcPrivateSubnet2Subnet3788AAA1"
}
]
}
}
}
}

0 comments on commit 387676f

Please sign in to comment.