-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
214 additions
and
55 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
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
Empty file.
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
37 changes: 37 additions & 0 deletions
37
test/unit/rules/jsonschema/test_cfn_lint_relationship_bad_path.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,37 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from collections import deque | ||
|
||
import pytest | ||
|
||
from cfnlint.context import Path | ||
from cfnlint.rules.jsonschema.CfnLintRelationship import CfnLintRelationship | ||
|
||
|
||
@pytest.fixture | ||
def rule(): | ||
return CfnLintRelationship(keywords=[], relationship="Resources") | ||
|
||
|
||
@pytest.fixture | ||
def template(): | ||
return { | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Resources": {}, | ||
} | ||
|
||
|
||
def test_get_relationships(rule, validator): | ||
validator = validator.evolve( | ||
context=validator.context.evolve( | ||
path=Path( | ||
deque(["Resources", "ParentOne", "Properties", "ImageId"]), | ||
), | ||
), | ||
) | ||
assert [] == list(rule.get_relationship(validator)) |
78 changes: 78 additions & 0 deletions
78
test/unit/rules/jsonschema/test_cfn_lint_relationship_list.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,78 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from collections import deque | ||
|
||
import pytest | ||
|
||
from cfnlint.context import Path | ||
from cfnlint.rules.jsonschema.CfnLintRelationship import CfnLintRelationship | ||
|
||
|
||
@pytest.fixture | ||
def rule(): | ||
return CfnLintRelationship( | ||
keywords=[], relationship="Resources/AWS::EC2::Instance/Properties/Foo/*/Bar" | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def template(): | ||
return { | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Resources": { | ||
"One": { | ||
"Type": "AWS::EC2::Instance", | ||
"Properties": { | ||
"Foo": [ | ||
{ | ||
"Bar": "One", | ||
}, | ||
{ | ||
"Bar": "Two", | ||
}, | ||
] | ||
}, | ||
}, | ||
"ParentOne": { | ||
"Type": "AWS::EC2::Instance", | ||
"Properties": {"ImageId": {"Fn::GetAtt": ["One", "ImageId"]}}, | ||
}, | ||
}, | ||
} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"name,path,status,expected", | ||
[ | ||
( | ||
"One", | ||
deque(["Resources", "ParentOne", "Properties", "ImageId"]), | ||
{}, | ||
[ | ||
("One", {}), | ||
("Two", {}), | ||
], | ||
), | ||
], | ||
) | ||
def test_get_relationships(name, path, status, expected, rule, validator): | ||
validator = validator.evolve( | ||
context=validator.context.evolve( | ||
path=Path(path), | ||
conditions=validator.context.conditions.evolve( | ||
status=status, | ||
), | ||
), | ||
) | ||
results = list(rule.get_relationship(validator)) | ||
assert len(results) == len(expected), f"Test {name!r} got {len(results)!r}" | ||
for result, exp in zip(results, expected): | ||
assert result[0] == exp[0], f"Test {name!r} got {result[0]!r}" | ||
assert ( | ||
result[1].context.conditions.status == exp[1] | ||
), f"Test {name!r} got {result[1].context.conditions.status!r}" |