-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Fn::Length in Fn::Select (#3633)
- Loading branch information
Showing
3 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
test/unit/rules/functions/test_select_language_extension.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
from collections import deque | ||
|
||
import pytest | ||
|
||
from cfnlint.jsonschema import ValidationError | ||
from cfnlint.rules.functions.Select import Select | ||
from cfnlint.rules.functions.SelectResolved import SelectResolved | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rule(): | ||
rule = Select() | ||
rule.child_rules["W1035"] = SelectResolved() | ||
yield rule | ||
|
||
|
||
@pytest.fixture | ||
def template(): | ||
return {"Transform": "AWS::LanguageExtensions"} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"name,instance,schema,expected", | ||
[ | ||
( | ||
"Invalid Fn::Select using an invalid function for index", | ||
{"Fn::Select": [{"Fn::GetAtt": "MyResource"}, ["bar"]]}, | ||
{"type": "string"}, | ||
[ | ||
ValidationError( | ||
"{'Fn::GetAtt': 'MyResource'} is not of type 'integer'", | ||
path=deque(["Fn::Select", 0]), | ||
schema_path=deque(["fn_items", "type"]), | ||
validator="fn_select", | ||
), | ||
], | ||
), | ||
( | ||
"Valid Fn::Length with language extension", | ||
{"Fn::Select": [{"Fn::Length": [1, 2]}, ["A", "B", "C"]]}, | ||
{"type": "string"}, | ||
[], | ||
), | ||
], | ||
) | ||
def test_validate(name, instance, schema, expected, rule, validator): | ||
errs = list(rule.fn_select(validator, schema, instance, {})) | ||
assert errs == expected, f"Test {name!r} got {errs!r}" |