@@ -46,15 +46,15 @@ def context(cfn):
46
46
{"Fn::FindInMap" : ["A" , "B" , "C" ]},
47
47
{"type" : "string" },
48
48
{},
49
- [] ,
49
+ None ,
50
50
[],
51
51
),
52
52
(
53
53
"Invalid Fn::FindInMap too long" ,
54
54
{"Fn::FindInMap" : ["foo" , "bar" , "key" , "key2" ]},
55
55
{"type" : "string" },
56
56
{},
57
- [] ,
57
+ None ,
58
58
[
59
59
ValidationError (
60
60
"['foo', 'bar', 'key', 'key2'] is too long (3)" ,
@@ -69,7 +69,7 @@ def context(cfn):
69
69
{"Fn::FindInMap" : {"foo" : "bar" }},
70
70
{"type" : "string" },
71
71
{},
72
- [] ,
72
+ None ,
73
73
[
74
74
ValidationError (
75
75
"{'foo': 'bar'} is not of type 'array'" ,
@@ -84,7 +84,7 @@ def context(cfn):
84
84
{"Fn::FindInMap" : [{"Fn::GetAtt" : "MyResource.Arn" }, "foo" , "bar" ]},
85
85
{"type" : "string" },
86
86
{},
87
- [] ,
87
+ None ,
88
88
[
89
89
ValidationError (
90
90
"{'Fn::GetAtt': 'MyResource.Arn'} is not of type 'string'" ,
@@ -99,15 +99,15 @@ def context(cfn):
99
99
{"Fn::FindInMap" : ["A" , "B" , "C" , {"DefaultValue" : "D" }]},
100
100
{"type" : "string" },
101
101
{"transforms" : Transforms (["AWS::LanguageExtensions" ])},
102
- [] ,
102
+ None ,
103
103
[],
104
104
),
105
105
(
106
106
"Invalid Fn::FindInMap options not of type object" ,
107
107
{"Fn::FindInMap" : ["A" , "B" , "C" , []]},
108
108
{"type" : "string" },
109
109
{"transforms" : Transforms (["AWS::LanguageExtensions" ])},
110
- [] ,
110
+ None ,
111
111
[
112
112
ValidationError (
113
113
"[] is not of type 'object'" ,
@@ -122,7 +122,7 @@ def context(cfn):
122
122
{"Fn::FindInMap" : ["A" , "B" , "C" , {}]},
123
123
{"type" : "string" },
124
124
{"transforms" : Transforms (["AWS::LanguageExtensions" ])},
125
- [] ,
125
+ None ,
126
126
[
127
127
ValidationError (
128
128
"'DefaultValue' is a required property" ,
@@ -147,6 +147,21 @@ def context(cfn):
147
147
),
148
148
],
149
149
),
150
+ (
151
+ "Valid Fn::FindInMap with a Ref to AWS::NoValue" ,
152
+ {
153
+ "Fn::FindInMap" : [
154
+ "A" ,
155
+ "B" ,
156
+ "C" ,
157
+ {"DefaultValue" : {"Ref" : "AWS::NoValue" }},
158
+ ]
159
+ },
160
+ {"type" : "string" },
161
+ {"transforms" : Transforms (["AWS::LanguageExtensions" ])},
162
+ [],
163
+ [],
164
+ ),
150
165
],
151
166
)
152
167
def test_validate (
@@ -162,10 +177,14 @@ def test_validate(
162
177
):
163
178
context = context .evolve (** context_evolve )
164
179
ref_mock = MagicMock ()
165
- ref_mock .return_value = iter (ref_mock_values )
180
+ ref_mock .return_value = iter (ref_mock_values or [] )
166
181
validator = CfnTemplateValidator ({}).extend (validators = {"ref" : ref_mock })(
167
182
context = context , cfn = cfn
168
183
)
169
184
errs = list (rule .fn_findinmap (validator , schema , instance , {}))
170
- assert ref_mock .call_count == len (ref_mock_values )
185
+
186
+ if ref_mock_values is None :
187
+ ref_mock .assert_not_called ()
188
+ else :
189
+ assert ref_mock .call_count == len (ref_mock_values ) or 1
171
190
assert errs == expected , f"Test { name !r} got { errs !r} "
0 commit comments