MCPcopy Create free account
hub / github.com/aws-cloudformation/rain / TestParseModuleConfigWithFnForEach

Function TestParseModuleConfigWithFnForEach

cft/module_config_test.go:197–257  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

195}
196
197func TestParseModuleConfigWithFnForEach(t *testing.T) {
198 // Create a test Template
199 template := &Template{}
200
201 // Test case: Fn::ForEach module configuration
202 forEachYaml := `
203- item
204- !Ref MyList
205- OutputKey:
206 Source: ./module.yaml
207 Properties:
208 Name: !Sub test-${item}
209`
210 forEachConfig, err := template.ParseModuleConfig("Fn::ForEach:LoopModule",
211 unmarshalYaml(t, forEachYaml))
212 if err != nil {
213 t.Errorf("ParseModuleConfig failed for Fn::ForEach: %v", err)
214 }
215
216 if forEachConfig.FnForEach == nil {
217 t.Errorf("Expected FnForEach to be non-nil")
218 }
219
220 if forEachConfig.FnForEach.LoopName != "LoopModule" {
221 t.Errorf("Expected LoopName=LoopModule, got %s",
222 forEachConfig.FnForEach.LoopName)
223 }
224
225 if forEachConfig.FnForEach.Identifier != "item" {
226 t.Errorf("Expected Identifier=item, got %s",
227 forEachConfig.FnForEach.Identifier)
228 }
229
230 if forEachConfig.FnForEach.OutputKey != "OutputKey" {
231 t.Errorf("Expected OutputKey=OutputKey, got %s",
232 forEachConfig.FnForEach.OutputKey)
233 }
234
235 // Test invalid Fn::ForEach (wrong number of elements)
236 invalidForEachYaml := `
237- item
238- !Ref MyList
239`
240 _, err = template.ParseModuleConfig("Fn::ForEach:InvalidLoop",
241 unmarshalYaml(t, invalidForEachYaml))
242 if err == nil {
243 t.Errorf("Expected error for invalid Fn::ForEach, got nil")
244 }
245
246 // Test invalid Fn::ForEach (invalid output mapping)
247 invalidOutputYaml := `
248- item
249- !Ref MyList
250- InvalidOutput
251`
252 _, err = template.ParseModuleConfig("Fn::ForEach:InvalidOutput",
253 unmarshalYaml(t, invalidOutputYaml))
254 if err == nil {

Callers

nothing calls this directly

Calls 2

ParseModuleConfigMethod · 0.95
unmarshalYamlFunction · 0.85

Tested by

no test coverage detected