-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V1 - cleanup config and add more tests (#3204)
* Add more testing to increase coverage * Create fixes and more tests
- Loading branch information
Showing
10 changed files
with
314 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
import pytest | ||
|
||
from cfnlint.context.context import _init_conditions | ||
|
||
|
||
def test_conditions(): | ||
with pytest.raises(ValueError): | ||
_init_conditions([]) |
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,104 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
from collections import namedtuple | ||
|
||
import pytest | ||
|
||
from cfnlint import Template | ||
from cfnlint.context.context import create_context_for_template | ||
|
||
_Counts = namedtuple("_Counts", ["resources", "parameters", "conditions", "mappings"]) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"name,instance,counts", | ||
[ | ||
( | ||
"Valid template", | ||
{ | ||
"Parameters": { | ||
"Env": { | ||
"Type": "String", | ||
} | ||
}, | ||
"Conditions": { | ||
"IsUsEast1": {"Fn::Equals": [{"Ref": "AWS::Region"}, "us-east-1"]} | ||
}, | ||
"Mappings": {"Map": {"us-east-1": {"foo": "bar"}}}, | ||
"Resources": { | ||
"Bucket": { | ||
"Type": "AWS::S3::Bucket", | ||
}, | ||
}, | ||
}, | ||
_Counts(resources=1, parameters=1, conditions=1, mappings=1), | ||
), | ||
( | ||
"Bad types in template", | ||
{ | ||
"Parameters": [], | ||
"Conditions": [], | ||
"Mappings": [], | ||
"Resources": [], | ||
}, | ||
_Counts(resources=0, parameters=0, conditions=0, mappings=0), | ||
), | ||
( | ||
"Invalid type configurations", | ||
{ | ||
"Parameters": { | ||
"BusinessUnit": [], | ||
"Env": { | ||
"Type": "String", | ||
}, | ||
}, | ||
"Mappings": {"AnotherMap": [], "Map": {"us-east-1": {"foo": "bar"}}}, | ||
"Resources": { | ||
"Instance": [], | ||
"Bucket": { | ||
"Type": "AWS::S3::Bucket", | ||
}, | ||
}, | ||
}, | ||
_Counts(resources=1, parameters=1, conditions=0, mappings=1), | ||
), | ||
( | ||
"Invalid mapping second key", | ||
{ | ||
"Mappings": { | ||
"BadKey": { | ||
"Foo": [], | ||
}, | ||
"Map": {"us-east-1": {"foo": "bar"}}, | ||
}, | ||
}, | ||
_Counts(resources=0, parameters=0, conditions=0, mappings=1), | ||
), | ||
( | ||
"Invalid mapping third key", | ||
{ | ||
"Mappings": { | ||
"BadKey": { | ||
"Foo": { | ||
"Bar": {}, | ||
}, | ||
}, | ||
"Map": {"us-east-1": {"foo": "bar"}}, | ||
}, | ||
}, | ||
_Counts(resources=0, parameters=0, conditions=0, mappings=1), | ||
), | ||
], | ||
) | ||
def test_create_context(name, instance, counts): | ||
cfn = Template("", instance, ["us-east-1"]) | ||
context = create_context_for_template(cfn) | ||
|
||
for i in counts._fields: | ||
assert len(getattr(context, i)) == getattr(counts, i), ( | ||
f"Test {name} has {i} {len(getattr(context, i))} " | ||
"and expected {getattr(counts, i)}" | ||
) |
Oops, something went wrong.