-
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.
Update E3615 to validate all CloudWatch Alarm periods (#3556)
- Loading branch information
Showing
5 changed files
with
160 additions
and
109 deletions.
There are no files selected for viewing
29 changes: 0 additions & 29 deletions
29
src/cfnlint/data/schemas/extensions/aws_cloudwatch_alarm/aws_namespace_period.json
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
src/cfnlint/data/schemas/extensions/aws_cloudwatch_alarm/period.json
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 @@ | ||
{ | ||
"additionalProperties": true, | ||
"description": "The period, in seconds, over which the statistic is applied. This is required for an alarm based on a metric. Valid values are 10, 30, 60, and any multiple of 60.", | ||
"if": { | ||
"properties": { | ||
"Period": { | ||
"type": [ | ||
"integer", | ||
"string" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"Period" | ||
], | ||
"type": "object" | ||
}, | ||
"then": { | ||
"properties": { | ||
"Period": { | ||
"else": { | ||
"multipleOf": 60 | ||
}, | ||
"if": { | ||
"maximum": 60 | ||
}, | ||
"then": { | ||
"enum": [ | ||
10, | ||
30, | ||
60 | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
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
71 changes: 0 additions & 71 deletions
71
test/unit/rules/resources/cloudwatch/test_alarm_aws_namespace_period.py
This file was deleted.
Oops, something went wrong.
116 changes: 116 additions & 0 deletions
116
test/unit/rules/resources/cloudwatch/test_alarm_period.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,116 @@ | ||
""" | ||
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.resources.cloudwatch.AlarmPeriod import AlarmPeriod | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rule(): | ||
rule = AlarmPeriod() | ||
yield rule | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"instance,expected", | ||
[ | ||
( | ||
{ | ||
"Period": 60, | ||
}, | ||
[], | ||
), | ||
( | ||
[], # wrong type | ||
[], | ||
), | ||
( | ||
{ | ||
"Period": {"Ref": "Period"}, # ignore when object | ||
}, | ||
[], | ||
), | ||
( | ||
{ | ||
"Period": 30, | ||
}, | ||
[], | ||
), | ||
( | ||
{ | ||
"Period": 600, | ||
}, | ||
[], | ||
), | ||
( | ||
{ | ||
"Period": 45, | ||
}, | ||
[ | ||
ValidationError( | ||
"45 is not one of [10, 30, 60] or a multiple of 60", | ||
rule=AlarmPeriod(), | ||
path=deque(["Period"]), | ||
validator="enum", | ||
schema_path=deque(["then", "properties", "Period", "then", "enum"]), | ||
) | ||
], | ||
), | ||
( | ||
{ | ||
"Period": "45", | ||
}, | ||
[ | ||
ValidationError( | ||
"'45' is not one of [10, 30, 60] or a multiple of 60", | ||
rule=AlarmPeriod(), | ||
path=deque(["Period"]), | ||
validator="enum", | ||
schema_path=deque(["then", "properties", "Period", "then", "enum"]), | ||
) | ||
], | ||
), | ||
( | ||
{ | ||
"Period": 121, | ||
}, | ||
[ | ||
ValidationError( | ||
"121 is not one of [10, 30, 60] or a multiple of 60", | ||
rule=AlarmPeriod(), | ||
path=deque(["Period"]), | ||
validator="multipleOf", | ||
schema_path=deque( | ||
["then", "properties", "Period", "else", "multipleOf"] | ||
), | ||
) | ||
], | ||
), | ||
( | ||
{ | ||
"Period": "121", | ||
}, | ||
[ | ||
ValidationError( | ||
"'121' is not one of [10, 30, 60] or a multiple of 60", | ||
rule=AlarmPeriod(), | ||
path=deque(["Period"]), | ||
validator="multipleOf", | ||
schema_path=deque( | ||
["then", "properties", "Period", "else", "multipleOf"] | ||
), | ||
) | ||
], | ||
), | ||
], | ||
) | ||
def test_validate(instance, expected, rule, validator): | ||
errs = list(rule.validate(validator, "", instance, {})) | ||
|
||
assert errs == expected, f"Expected {expected} got {errs}" |