kumogata-template 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +54 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +75 -0
  6. data/README.md +204 -0
  7. data/Rakefile +23 -0
  8. data/bin/kumogata-template +9 -0
  9. data/kumogata-template.gemspec +26 -0
  10. data/lib/kumogata/template.rb +17 -0
  11. data/lib/kumogata/template/autoscaling.rb +77 -0
  12. data/lib/kumogata/template/cloudwatch.rb +28 -0
  13. data/lib/kumogata/template/codedeploy.rb +85 -0
  14. data/lib/kumogata/template/const.rb +175 -0
  15. data/lib/kumogata/template/datapipeline.rb +90 -0
  16. data/lib/kumogata/template/dynamodb.rb +111 -0
  17. data/lib/kumogata/template/ec2.rb +165 -0
  18. data/lib/kumogata/template/ecs.rb +119 -0
  19. data/lib/kumogata/template/elasticbeanstalk.rb +33 -0
  20. data/lib/kumogata/template/elb.rb +132 -0
  21. data/lib/kumogata/template/emr.rb +166 -0
  22. data/lib/kumogata/template/events.rb +25 -0
  23. data/lib/kumogata/template/ext/argument_parser.rb +8 -0
  24. data/lib/kumogata/template/ext/kumogata.rb +103 -0
  25. data/lib/kumogata/template/helper.rb +211 -0
  26. data/lib/kumogata/template/iam.rb +96 -0
  27. data/lib/kumogata/template/lambda.rb +34 -0
  28. data/lib/kumogata/template/s3.rb +223 -0
  29. data/lib/kumogata/template/sns.rb +25 -0
  30. data/lib/kumogata/template/version.rb +1 -0
  31. data/template/_template.rb +25 -0
  32. data/template/autoscaling-group.rb +47 -0
  33. data/template/autoscaling-launch-configuration.rb +54 -0
  34. data/template/autoscaling-lifecycle-hook.rb +27 -0
  35. data/template/autoscaling-scaling-policy.rb +33 -0
  36. data/template/autoscaling-scheduled-action.rb +37 -0
  37. data/template/cloudtrail.rb +39 -0
  38. data/template/cloudwatch-alarm.rb +45 -0
  39. data/template/codedeploy-application.rb +15 -0
  40. data/template/codedeploy-deployment-config.rb +23 -0
  41. data/template/codedeploy-deployment-group.rb +35 -0
  42. data/template/datapipeline-pipeline.rb +28 -0
  43. data/template/dynamodb-table.rb +33 -0
  44. data/template/ec2-eip-association.rb +23 -0
  45. data/template/ec2-eip.rb +17 -0
  46. data/template/ec2-instance.rb +65 -0
  47. data/template/ec2-internet-gateway.rb +15 -0
  48. data/template/ec2-nat-gateway.rb +17 -0
  49. data/template/ec2-network-acl-entry.rb +30 -0
  50. data/template/ec2-network-acl.rb +17 -0
  51. data/template/ec2-route-table.rb +17 -0
  52. data/template/ec2-route.rb +27 -0
  53. data/template/ec2-security-group.rb +24 -0
  54. data/template/ec2-subnet-network-acl-association.rb +17 -0
  55. data/template/ec2-subnet-route-table-association.rb +17 -0
  56. data/template/ec2-subnet.rb +23 -0
  57. data/template/ec2-volume-attachment.rb +19 -0
  58. data/template/ec2-volume.rb +31 -0
  59. data/template/ec2-vpc-endpoint.rb +23 -0
  60. data/template/ec2-vpc-gateway-attachment.rb +19 -0
  61. data/template/ec2-vpc.rb +24 -0
  62. data/template/ecs-cluster.rb +11 -0
  63. data/template/ecs-service.rb +24 -0
  64. data/template/ecs-task-definition.rb +18 -0
  65. data/template/elasticache-cache-cluster.rb +63 -0
  66. data/template/elasticache-parameter-group.rb +20 -0
  67. data/template/elasticache-replication-group.rb +58 -0
  68. data/template/elasticache-subnet-group.rb +17 -0
  69. data/template/elasticbeanstalk-application-version.rb +24 -0
  70. data/template/elasticbeanstalk-application.rb +17 -0
  71. data/template/elasticbeanstalk-configuration-template.rb +31 -0
  72. data/template/elasticbeanstalk-environment.rb +44 -0
  73. data/template/elb-loadbalancer.rb +46 -0
  74. data/template/emr-cluster.rb +39 -0
  75. data/template/emr-instance-group-config.rb +33 -0
  76. data/template/emr-step.rb +22 -0
  77. data/template/events-rule.rb +28 -0
  78. data/template/iam-access-key.rb +19 -0
  79. data/template/iam-group.rb +20 -0
  80. data/template/iam-instance-profile.rb +17 -0
  81. data/template/iam-managed-policy.rb +28 -0
  82. data/template/iam-policy.rb +26 -0
  83. data/template/iam-role.rb +21 -0
  84. data/template/iam-user-to-group-addition.rb +17 -0
  85. data/template/iam-user.rb +24 -0
  86. data/template/lambda-alias.rb +21 -0
  87. data/template/lambda-event-source-mapping.rb +24 -0
  88. data/template/lambda-function.rb +34 -0
  89. data/template/lambda-permission.rb +26 -0
  90. data/template/lambda-version.rb +19 -0
  91. data/template/mappings-ec2.rb +85 -0
  92. data/template/output-access-key.rb +6 -0
  93. data/template/output-arn.rb +6 -0
  94. data/template/output-autoscaling.rb +6 -0
  95. data/template/output-az.rb +6 -0
  96. data/template/output-dynamodb.rb +6 -0
  97. data/template/output-ec2.rb +8 -0
  98. data/template/output-elasticache.rb +30 -0
  99. data/template/output-elb.rb +12 -0
  100. data/template/output-emr.rb +6 -0
  101. data/template/output-rds.rb +10 -0
  102. data/template/output-redshift.rb +10 -0
  103. data/template/output-s3.rb +8 -0
  104. data/template/output-security-group.rb +5 -0
  105. data/template/output-sqs.rb +5 -0
  106. data/template/output-topic.rb +6 -0
  107. data/template/output-vpc.rb +10 -0
  108. data/template/output.rb +29 -0
  109. data/template/parameter-ec2.rb +22 -0
  110. data/template/parameter-elasticache.rb +9 -0
  111. data/template/parameter-rds.rb +9 -0
  112. data/template/parameter-redshift.rb +9 -0
  113. data/template/parameter.rb +20 -0
  114. data/template/rds-db-cluster-parameter-group.rb +22 -0
  115. data/template/rds-db-cluster.rb +47 -0
  116. data/template/rds-db-instance.rb +82 -0
  117. data/template/rds-db-parameter-group.rb +21 -0
  118. data/template/rds-db-subnet-group.rb +19 -0
  119. data/template/rds-event-subscription.rb +42 -0
  120. data/template/rds-option-group.rb +23 -0
  121. data/template/redshift-cluster-parameter-group.rb +19 -0
  122. data/template/redshift-cluster-subnet-group.rb +17 -0
  123. data/template/redshift-cluster.rb +60 -0
  124. data/template/s3-bucket-policy.rb +20 -0
  125. data/template/s3-bucket.rb +42 -0
  126. data/template/sns-topic.rb +20 -0
  127. data/template/sqs-queue.rb +27 -0
  128. data/test/_template.rb +26 -0
  129. data/test/abstract_unit.rb +101 -0
  130. data/test/autoscaling_test.rb +109 -0
  131. data/test/codedeploy_test.rb +117 -0
  132. data/test/datapipeline_test.rb +142 -0
  133. data/test/dynamodb_test.rb +184 -0
  134. data/test/ec2_test.rb +286 -0
  135. data/test/ecs_test.rb +135 -0
  136. data/test/elasticbeanstalk_test.rb +56 -0
  137. data/test/elb_test.rb +147 -0
  138. data/test/emr_test.rb +193 -0
  139. data/test/events_test.rb +22 -0
  140. data/test/helper_test.rb +547 -0
  141. data/test/iam_test.rb +93 -0
  142. data/test/lambda_test.rb +41 -0
  143. data/test/s3_test.rb +195 -0
  144. data/test/sns_test.rb +27 -0
  145. data/test/template/autoscaling-group_test.rb +177 -0
  146. data/test/template/autoscaling-launch-configuration_test.rb +117 -0
  147. data/test/template/autoscaling-lifecycle-hook_test.rb +33 -0
  148. data/test/template/autoscaling-scaling-policy_test.rb +26 -0
  149. data/test/template/autoscaling-scheduled-action_test.rb +26 -0
  150. data/test/template/cloudtrail_test.rb +55 -0
  151. data/test/template/cloudwatch-alarm_test.rb +38 -0
  152. data/test/template/codedeploy-application_test.rb +21 -0
  153. data/test/template/codedeploy-deployment-config_test.rb +26 -0
  154. data/test/template/codedeploy-deployment-group_test.rb +48 -0
  155. data/test/template/datapipeline-pipeline_test.rb +358 -0
  156. data/test/template/dynamodb-table_test.rb +94 -0
  157. data/test/template/ec2-eip-association_test.rb +22 -0
  158. data/test/template/ec2-eip_test.rb +21 -0
  159. data/test/template/ec2-instance_test.rb +95 -0
  160. data/test/template/ec2-internet-gateway_test.rb +48 -0
  161. data/test/template/ec2-nat-gateway_test.rb +22 -0
  162. data/test/template/ec2-network-acl-entry_test.rb +61 -0
  163. data/test/template/ec2-network-acl_test.rb +51 -0
  164. data/test/template/ec2-route-table_test.rb +49 -0
  165. data/test/template/ec2-route_test.rb +21 -0
  166. data/test/template/ec2-security-group_test.rb +50 -0
  167. data/test/template/ec2-subnet-netwokr-acl-association_test.rb +26 -0
  168. data/test/template/ec2-subnet-route-table-association_test.rb +22 -0
  169. data/test/template/ec2-subnet_test.rb +51 -0
  170. data/test/template/ec2-volume-attachment_test.rb +24 -0
  171. data/test/template/ec2-volume_test.rb +52 -0
  172. data/test/template/ec2-vpc-gateway-attachment_test.rb +23 -0
  173. data/test/template/ec2-vpc_test.rb +102 -0
  174. data/test/template/ecs-cluster_test.rb +18 -0
  175. data/test/template/ecs-service_test.rb +29 -0
  176. data/test/template/ecs-task-definition_test.rb +143 -0
  177. data/test/template/elasticache-cache-cluster_test.rb +77 -0
  178. data/test/template/elasticache-parameter-group_test.rb +25 -0
  179. data/test/template/elasticache-replication-group_test.rb +45 -0
  180. data/test/template/elasticache-subnet-group_test.rb +26 -0
  181. data/test/template/elasticbeanstalk-application-version_test.rb +27 -0
  182. data/test/template/elasticbeanstalk-application_test.rb +21 -0
  183. data/test/template/elasticbeanstalk-configuration-template_test.rb +23 -0
  184. data/test/template/elasticbeanstalk-environment_test.rb +56 -0
  185. data/test/template/elasticbeanstalk-template_test.rb +33 -0
  186. data/test/template/elb-loadbalancer_test.rb +94 -0
  187. data/test/template/emr-cluster_test.rb +147 -0
  188. data/test/template/emr-instance-group-config_test.rb +65 -0
  189. data/test/template/emr-step_test.rb +82 -0
  190. data/test/template/events-rule_test.rb +34 -0
  191. data/test/template/iam-access-key_test.rb +22 -0
  192. data/test/template/iam-group_test.rb +21 -0
  193. data/test/template/iam-instance-profile_test.rb +24 -0
  194. data/test/template/iam-managed-policy_test.rb +35 -0
  195. data/test/template/iam-policy_test.rb +52 -0
  196. data/test/template/iam-role_test.rb +37 -0
  197. data/test/template/iam-user-to-group-addition_test.rb +24 -0
  198. data/test/template/iam-user_test.rb +21 -0
  199. data/test/template/lambda-alias_test.rb +46 -0
  200. data/test/template/lambda-event-source-mapping_test.rb +36 -0
  201. data/test/template/lambda-function_test.rb +34 -0
  202. data/test/template/lambda-permission_test.rb +32 -0
  203. data/test/template/lambda-version_test.rb +27 -0
  204. data/test/template/mappings-ec2_test.rb +92 -0
  205. data/test/template/output-access-key_test.rb +30 -0
  206. data/test/template/output-arn_test.rb +30 -0
  207. data/test/template/output-autoscaling_test.rb +27 -0
  208. data/test/template/output-az_test.rb +31 -0
  209. data/test/template/output-dynamodb_test.rb +21 -0
  210. data/test/template/output-ec2_test.rb +82 -0
  211. data/test/template/output-elasticache_test.rb +107 -0
  212. data/test/template/output-elb_test.rb +48 -0
  213. data/test/template/output-emr_test.rb +30 -0
  214. data/test/template/output-rds_test.rb +39 -0
  215. data/test/template/output-redshift_test.rb +39 -0
  216. data/test/template/output-s3_test.rb +52 -0
  217. data/test/template/output-security-group_test.rb +21 -0
  218. data/test/template/output-sqs_test.rb +21 -0
  219. data/test/template/output-topic_test.rb +30 -0
  220. data/test/template/output-vpc_test.rb +48 -0
  221. data/test/template/output_test.rb +87 -0
  222. data/test/template/parameter-ec2_test.rb +44 -0
  223. data/test/template/parameter-elasticache_test.rb +30 -0
  224. data/test/template/parameter-rds_test.rb +30 -0
  225. data/test/template/parameter-redshift_test.rb +30 -0
  226. data/test/template/parameter_test.rb +40 -0
  227. data/test/template/rds-db-cluster-parameter-group_test.rb +53 -0
  228. data/test/template/rds-db-cluster_test.rb +84 -0
  229. data/test/template/rds-db-instance_test.rb +93 -0
  230. data/test/template/rds-db-parameter-group_test.rb +53 -0
  231. data/test/template/rds-db-subnet-group.rb +54 -0
  232. data/test/template/rds-event-subscription_test.rb +48 -0
  233. data/test/template/rds-option-group_test.rb +56 -0
  234. data/test/template/redshift-cluster-parameter-group_test.rb +28 -0
  235. data/test/template/redshift-cluster-subnet-group_test.rb +26 -0
  236. data/test/template/redshift-cluster_test.rb +47 -0
  237. data/test/template/s3-bucket-policy_test.rb +40 -0
  238. data/test/template/s3-bucket_test.rb +127 -0
  239. data/test/template/sns-topic_test.rb +42 -0
  240. data/test/template/sqs-queue_test.rb +25 -0
  241. metadata +468 -0
@@ -0,0 +1,22 @@
1
+ require 'abstract_unit'
2
+ require 'kumogata/template/events'
3
+
4
+ class EventsTest < Minitest::Test
5
+ def test_events_target
6
+ template = <<-EOS
7
+ Test _events_targets({ targets: [ { arn: "test", id: "test" } ] })
8
+ EOS
9
+ act_template = run_client_as_json(template)
10
+ exp_template = <<-EOS
11
+ {
12
+ "Test": [
13
+ {
14
+ "Arn": "test",
15
+ "Id": "test"
16
+ }
17
+ ]
18
+ }
19
+ EOS
20
+ assert_equal exp_template.chomp, act_template
21
+ end
22
+ end
@@ -0,0 +1,547 @@
1
+ require 'abstract_unit'
2
+ require 'kumogata/template/helper'
3
+
4
+ class HelperTest < Minitest::Test
5
+ def test_resource_name
6
+ assert_equal _resource_name("test"), "Test"
7
+ assert_equal _resource_name("test", "Resource"), "TestResource"
8
+ assert_equal _resource_name("test-name", "Resource"), "TestnameResource"
9
+ assert_equal _resource_name("test Name", "Resource"), "TestNameResource"
10
+ end
11
+
12
+ def test_array
13
+ assert_equal _array("test"), [ "test" ]
14
+ assert_equal _array([ "test" ]), [ "test" ]
15
+ assert_equal _array({ test: "test" }), [ "test" ]
16
+ end
17
+
18
+ def test_bool
19
+ assert_equal _bool("test", { test: true }), "true"
20
+ assert_equal _bool("test", { test: false }), "false"
21
+ assert_equal _bool("test", { test1: false }, true), "true"
22
+ assert_equal _bool("test", { test1: false }, false), "false"
23
+ end
24
+
25
+ def test_capitalize
26
+ assert_equal _capitalize("test test"), "TestTest"
27
+ end
28
+
29
+ def test_valid_values
30
+ assert_equal _valid_values("test1", ["test1", "test2"]), "test1"
31
+ assert_equal _valid_values("test3", ["test1", "test2"], "test1"), "test1"
32
+ assert_equal _valid_values("test1", ["Test1", "Test2"], "Test1"), "Test1"
33
+ end
34
+
35
+ def test_valid_numbers
36
+ assert_equal _valid_numbers(1, 0, 1, 2), 1
37
+ assert_equal _valid_numbers(2, 1, 2, 4), 2
38
+ assert_equal _valid_numbers(2, 0, 1, 2), 2
39
+ assert_equal _valid_numbers(3, 0, 1), nil
40
+ assert_equal _valid_numbers(nil, 0, 1), nil
41
+ end
42
+
43
+ def test_ref_string
44
+ template = <<-EOS
45
+ Test _ref_string("test", {})
46
+ EOS
47
+ act_template = run_client_as_json(template)
48
+ exp_template = <<-EOS
49
+ {
50
+ "Test": ""
51
+ }
52
+ EOS
53
+ assert_equal exp_template.chomp, act_template
54
+
55
+ template = <<-EOS
56
+ Test _ref_string("test", test: "test")
57
+ EOS
58
+ act_template = run_client_as_json(template)
59
+ exp_template = <<-EOS
60
+ {
61
+ "Test": "test"
62
+ }
63
+ EOS
64
+ assert_equal exp_template.chomp, act_template
65
+ end
66
+
67
+ def test_ref_array
68
+ assert_equal _ref_array("tests", name: "array"), []
69
+
70
+ template = <<-EOS
71
+ Tests _ref_array("tests", name: "tests", ref_tests: [ "test1", "test2" ])
72
+ EOS
73
+ act_template = run_client_as_json(template)
74
+ exp_template = <<-EOS
75
+ {
76
+ "Tests": [
77
+ {
78
+ "Ref": "Test1"
79
+ },
80
+ {
81
+ "Ref": "Test2"
82
+ }
83
+ ]
84
+ }
85
+ EOS
86
+ assert_equal exp_template.chomp, act_template
87
+
88
+ template = <<-EOS
89
+ Tests _ref_array("tests", { name: "tests", ref_tests: [ "test1", "test2" ] }, "test" )
90
+ EOS
91
+ act_template = run_client_as_json(template)
92
+ exp_template = <<-EOS
93
+ {
94
+ "Tests": [
95
+ {
96
+ "Ref": "Test1Test"
97
+ },
98
+ {
99
+ "Ref": "Test2Test"
100
+ }
101
+ ]
102
+ }
103
+ EOS
104
+ assert_equal exp_template.chomp, act_template
105
+
106
+ template = <<-EOS
107
+ Tests _ref_array("tests", name: "tests", ref_tests: "test1")
108
+ EOS
109
+ act_template = run_client_as_json(template)
110
+ exp_template = <<-EOS
111
+ {
112
+ "Tests": [
113
+ {
114
+ "Ref": "Test1"
115
+ }
116
+ ]
117
+ }
118
+ EOS
119
+ assert_equal exp_template.chomp, act_template
120
+ end
121
+
122
+ def test_ref_attr_string
123
+ template = <<-EOS
124
+ Test _ref_attr_string("test", "test1", test: "test")
125
+ EOS
126
+ act_template = run_client_as_json(template)
127
+ exp_template = <<-EOS
128
+ {
129
+ "Test": "test"
130
+ }
131
+ EOS
132
+ assert_equal exp_template.chomp, act_template
133
+
134
+ template = <<-EOS
135
+ Test _ref_attr_string("test", "test1", ref_test: "test")
136
+ EOS
137
+ act_template = run_client_as_json(template)
138
+ exp_template = <<-EOS
139
+ {
140
+ "Test": {
141
+ "Fn::GetAtt": [
142
+ "Test",
143
+ "test1"
144
+ ]
145
+ }
146
+ }
147
+ EOS
148
+ assert_equal exp_template.chomp, act_template
149
+ end
150
+
151
+ def test_ref_name
152
+ template = <<-EOS
153
+ Test _ref_name("test", test: "test")
154
+ EOS
155
+ act_template = run_client_as_json(template)
156
+ exp_template = <<-EOS
157
+ {
158
+ "Test": "test"
159
+ }
160
+ EOS
161
+ assert_equal exp_template.chomp, act_template
162
+
163
+ template = <<-EOS
164
+ Test _ref_name("test", test: "test test")
165
+ EOS
166
+ act_template = run_client_as_json(template)
167
+ exp_template = <<-EOS
168
+ {
169
+ "Test": "test-test"
170
+ }
171
+ EOS
172
+ assert_equal exp_template.chomp, act_template
173
+
174
+ template = <<-EOS
175
+ Test _ref_name("test", ref_test: "test")
176
+ EOS
177
+ act_template = run_client_as_json(template)
178
+ exp_template = <<-EOS
179
+ {
180
+ "Test": {
181
+ "Fn::Join": [
182
+ "-",
183
+ [
184
+ {
185
+ "Ref": "Service"
186
+ },
187
+ {
188
+ "Ref": "Test"
189
+ }
190
+ ]
191
+ ]
192
+ }
193
+ }
194
+ EOS
195
+ assert_equal exp_template.chomp, act_template
196
+
197
+ template = <<-EOS
198
+ Test _ref_name("test", {})
199
+ EOS
200
+ act_template = run_client_as_json(template)
201
+ exp_template = <<-EOS
202
+ {
203
+ "Test": {
204
+ "Fn::Join": [
205
+ "-",
206
+ [
207
+ {
208
+ "Ref": "Service"
209
+ },
210
+ {
211
+ "Ref": "Name"
212
+ }
213
+ ]
214
+ ]
215
+ }
216
+ }
217
+ EOS
218
+ assert_equal exp_template.chomp, act_template
219
+ end
220
+
221
+ def test_attr_string
222
+ template = <<-EOS
223
+ Test _attr_string("test", "test1")
224
+ EOS
225
+ act_template = run_client_as_json(template)
226
+ exp_template = <<-EOS
227
+ {
228
+ "Test": {
229
+ "Fn::GetAtt": [
230
+ "Test",
231
+ "test1"
232
+ ]
233
+ }
234
+ }
235
+ EOS
236
+ assert_equal exp_template.chomp, act_template
237
+ end
238
+
239
+ def test_find_in_map
240
+ template = <<-EOS
241
+ Test _find_in_map("Test", "test1", "test2")
242
+ EOS
243
+ act_template = run_client_as_json(template)
244
+ exp_template = <<-EOS
245
+ {
246
+ "Test": {
247
+ "Fn::FindInMap": [
248
+ "Test",
249
+ "test1",
250
+ "test2"
251
+ ]
252
+ }
253
+ }
254
+ EOS
255
+ assert_equal exp_template.chomp, act_template
256
+ end
257
+
258
+ def test_tag
259
+ template = <<-EOS
260
+ Test _tag(key: "test", value: "test")
261
+ EOS
262
+ act_template = run_client_as_json(template)
263
+ exp_template = <<-EOS
264
+ {
265
+ "Test": {
266
+ "Key": "Test",
267
+ "Value": "test"
268
+ }
269
+ }
270
+ EOS
271
+ assert_equal exp_template.chomp, act_template
272
+
273
+ template = <<-EOS
274
+ Test _tag({key: "ref_test", value: "test"})
275
+ EOS
276
+ act_template = run_client_as_json(template)
277
+ exp_template = <<-EOS
278
+ {
279
+ "Test": {
280
+ "Key": "Test",
281
+ "Value": {
282
+ "Ref": "Test"
283
+ }
284
+ }
285
+ }
286
+ EOS
287
+ assert_equal exp_template.chomp, act_template
288
+ end
289
+
290
+ def test_tags
291
+ template = <<-EOS
292
+ Test _tags(name: "test")
293
+ EOS
294
+ act_template = run_client_as_json(template)
295
+ exp_template = <<-EOS
296
+ {
297
+ "Test": [
298
+ {
299
+ "Key": "Name",
300
+ "Value": {
301
+ "Fn::Join": [
302
+ "-",
303
+ [
304
+ {
305
+ "Ref": "Service"
306
+ },
307
+ "test"
308
+ ]
309
+ ]
310
+ }
311
+ },
312
+ {
313
+ "Key": "Service",
314
+ "Value": {
315
+ "Ref": "Service"
316
+ }
317
+ },
318
+ {
319
+ "Key": "Version",
320
+ "Value": {
321
+ "Ref": "Version"
322
+ }
323
+ }
324
+ ]
325
+ }
326
+ EOS
327
+ assert_equal exp_template.chomp, act_template
328
+
329
+ template = <<-EOS
330
+ Test _tags({ name: "test", tags_append: { ref_test: "test" } })
331
+ EOS
332
+ act_template = run_client_as_json(template)
333
+ exp_template = <<-EOS
334
+ {
335
+ "Test": [
336
+ {
337
+ "Key": "Name",
338
+ "Value": {
339
+ "Fn::Join": [
340
+ "-",
341
+ [
342
+ {
343
+ "Ref": "Service"
344
+ },
345
+ "test"
346
+ ]
347
+ ]
348
+ }
349
+ },
350
+ {
351
+ "Key": "Service",
352
+ "Value": {
353
+ "Ref": "Service"
354
+ }
355
+ },
356
+ {
357
+ "Key": "Version",
358
+ "Value": {
359
+ "Ref": "Version"
360
+ }
361
+ },
362
+ {
363
+ "Key": "Test",
364
+ "Value": {
365
+ "Ref": "Test"
366
+ }
367
+ }
368
+ ]
369
+ }
370
+ EOS
371
+ assert_equal exp_template.chomp, act_template
372
+ end
373
+
374
+ def test_tag_name
375
+ template = <<-EOS
376
+ Test _tag_name("test")
377
+ EOS
378
+ act_template = run_client_as_json(template)
379
+ exp_template = <<-EOS
380
+ {
381
+ "Test": {
382
+ "Fn::Join": [
383
+ "-",
384
+ [
385
+ {
386
+ "Ref": "Service"
387
+ },
388
+ "test"
389
+ ]
390
+ ]
391
+ }
392
+ }
393
+ EOS
394
+ assert_equal exp_template.chomp, act_template
395
+ end
396
+
397
+ def test_availability_zone
398
+ template = <<-EOS
399
+ Test _availability_zone(ref_subnet: "test")
400
+ EOS
401
+ act_template = run_client_as_json(template)
402
+ exp_template = <<-EOS
403
+ {
404
+ "Test": {
405
+ "Fn::GetAtt": [
406
+ "TestSubnet",
407
+ "AvailabilityZone"
408
+ ]
409
+ }
410
+ }
411
+ EOS
412
+ assert_equal exp_template.chomp, act_template
413
+
414
+ template = <<-EOS
415
+ Test _availability_zone({ ref_subnet: "test", ref_az: "test" }, false)
416
+ EOS
417
+ act_template = run_client_as_json(template)
418
+ exp_template = <<-EOS
419
+ {
420
+ "Test": {
421
+ "Ref": "Test"
422
+ }
423
+ }
424
+ EOS
425
+ assert_equal exp_template.chomp, act_template
426
+
427
+ template = <<-EOS
428
+ Test _availability_zone({})
429
+ EOS
430
+ act_template = run_client_as_json(template)
431
+ exp_template = <<-EOS
432
+ {
433
+ "Test": ""
434
+ }
435
+ EOS
436
+ assert_equal exp_template.chomp, act_template
437
+ end
438
+
439
+ def test_availability_zones
440
+ template = <<-EOS
441
+ Test _availability_zones(ref_subnet: "test")
442
+ EOS
443
+ act_template = run_client_as_json(template)
444
+ exp_template = <<-EOS
445
+ {
446
+ "Test": [
447
+ {
448
+ "Fn::GetAtt": [
449
+ "TestSubnet",
450
+ "AvailabilityZone"
451
+ ]
452
+ }
453
+ ]
454
+ }
455
+ EOS
456
+ assert_equal exp_template.chomp, act_template
457
+
458
+ template = <<-EOS
459
+ Test _availability_zones(ref_subnets: [ "test" ])
460
+ EOS
461
+ act_template = run_client_as_json(template)
462
+ exp_template = <<-EOS
463
+ {
464
+ "Test": [
465
+ {
466
+ "Fn::GetAtt": [
467
+ "TestSubnet",
468
+ "AvailabilityZone"
469
+ ]
470
+ }
471
+ ]
472
+ }
473
+ EOS
474
+ assert_equal exp_template.chomp, act_template
475
+
476
+ template = <<-EOS
477
+ Test _availability_zones({ ref_subnet: "test", ref_azs: [ "test" ] }, false)
478
+ EOS
479
+ act_template = run_client_as_json(template)
480
+ exp_template = <<-EOS
481
+ {
482
+ "Test": [
483
+ {
484
+ "Ref": "TestZone"
485
+ }
486
+ ]
487
+ }
488
+ EOS
489
+ assert_equal exp_template.chomp, act_template
490
+
491
+ template = <<-EOS
492
+ Test _availability_zones({ ref_subnet: "test", ref_az: "test" }, false)
493
+ EOS
494
+ act_template = run_client_as_json(template)
495
+ exp_template = <<-EOS
496
+ {
497
+ "Test": [
498
+ {
499
+ "Ref": "TestZone"
500
+ }
501
+ ]
502
+ }
503
+ EOS
504
+ assert_equal exp_template.chomp, act_template
505
+
506
+ template = <<-EOS
507
+ Test _availability_zones({})
508
+ EOS
509
+ act_template = run_client_as_json(template)
510
+ exp_template = <<-EOS
511
+ {
512
+ "Test": {
513
+ "Fn::GetAZs": {
514
+ "Ref": "AWS::Region"
515
+ }
516
+ }
517
+ }
518
+ EOS
519
+ assert_equal exp_template.chomp, act_template
520
+ end
521
+
522
+ def test_timestamp_utc
523
+ assert_equal _timestamp_utc(2016, 4, 1), "2016-03-31T15:00:00Z"
524
+ end
525
+
526
+ def test_timestamp_utc_from_string
527
+ assert_equal _timestamp_utc_from_string("2016-04-01 00:00"), "2016-03-31T15:00:00Z"
528
+ end
529
+
530
+ def test_maintenance_window
531
+ start_time = Time.local(2016, 4, 1, 3, 30)
532
+ end_time = start_time + (60 * 60)
533
+ format = "%a:%H:%M"
534
+ utc_start_time = start_time.utc.strftime(format)
535
+ utc_end_time = end_time.utc.strftime(format)
536
+ assert_equal "#{utc_start_time}-#{utc_end_time}", _maintenance_window("elasticache", start_time)
537
+ end
538
+
539
+ def test_window_time
540
+ start_time = Time.local(2016, 4, 1, 3, 30)
541
+ end_time = start_time + (60 * 60)
542
+ format = "%H:%M"
543
+ utc_start_time = start_time.utc.strftime(format)
544
+ utc_end_time = end_time.utc.strftime(format)
545
+ assert_equal "#{utc_start_time}-#{utc_end_time}", _window_time("elasticache", start_time)
546
+ end
547
+ end