-
Notifications
You must be signed in to change notification settings - Fork 574
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving to new using schema structure for resource prop rules (#3236)
* Moving to new using schema structure for resource prop rules * Clean some tests for better coverage
- Loading branch information
Showing
6 changed files
with
199 additions
and
169 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
43 changes: 0 additions & 43 deletions
43
test/fixtures/templates/bad/resources/route53/recordset_name.yaml
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
test/fixtures/templates/good/resources/route53/recordset_name.yaml
This file was deleted.
Oops, something went wrong.
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,91 @@ | ||
""" | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: MIT-0 | ||
""" | ||
|
||
import pytest | ||
|
||
from cfnlint.context import Context | ||
from cfnlint.jsonschema import CfnTemplateValidator, ValidationError | ||
from cfnlint.rules.jsonschema.CfnLint import CfnLint | ||
from cfnlint.rules.jsonschema.CfnLintKeyword import CfnLintKeyword | ||
|
||
|
||
class _FooError(CfnLintKeyword): | ||
id = "EXXXX" | ||
shortdesc = "A rule" | ||
description = "A rule" | ||
|
||
def __init__(self) -> None: | ||
super().__init__(["Foo"]) | ||
|
||
def validate(self, validator, keywords, instance, schema): | ||
yield ValidationError("No Foo") | ||
|
||
|
||
class _BarError(CfnLintKeyword): | ||
id = "EYYYY" | ||
shortdesc = "A rule" | ||
description = "A rule" | ||
|
||
def __init__(self) -> None: | ||
super().__init__(["Bar"]) | ||
|
||
def validate(self, validator, keywords, instance, schema): | ||
yield ValidationError("No Bar", rule=self) | ||
|
||
|
||
class _SubError(CfnLintKeyword): | ||
def __init__(self) -> None: | ||
super().__init__(["Bar"]) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rule(): | ||
rule = CfnLint() | ||
rule.child_rules["EXXXX"] = _FooError() | ||
rule.child_rules["EYYYY"] = _BarError() | ||
rule.child_rules["EZZZZ"] = _SubError() | ||
yield rule | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"name,keywords,expected_errs", | ||
[ | ||
( | ||
"When no error in exception add it", | ||
["Foo"], | ||
[ | ||
ValidationError( | ||
message="No Foo", | ||
rule=_FooError(), | ||
), | ||
], | ||
), | ||
( | ||
"When no error in exception add it", | ||
["Foo", "Bar"], | ||
[ | ||
ValidationError( | ||
message="No Foo", | ||
rule=_FooError(), | ||
), | ||
ValidationError( | ||
message="No Bar", | ||
rule=_BarError(), | ||
), | ||
], | ||
), | ||
( | ||
"When no error in exception add it", | ||
["FooBar"], | ||
[], | ||
), | ||
], | ||
) | ||
def test_cfn_schema(name, keywords, expected_errs, rule): | ||
context = Context(regions=["us-east-1"]) | ||
validator = CfnTemplateValidator(schema={}, context=context) | ||
|
||
errs = list(rule.cfnLint(validator, keywords, True, {})) | ||
assert errs == expected_errs, f"{name} failed {errs} did not match {expected_errs}" |
Oops, something went wrong.