Skip to content

Commit

Permalink
More testing for log format name
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Jan 17, 2025
1 parent e705edd commit 08284a8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cfnlint/rules/formats/LogGroupName.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def format(self, validator: Validator, instance: Any) -> bool:
if not isinstance(instance, str):
return True

if re.match(r"^[.\-_/#A-Za-z0-9]{1,512}\Z", instance):
if re.match(r"^[\.\-_\/#A-Za-z0-9]{1,512}\Z", instance):
return True

return False
42 changes: 42 additions & 0 deletions test/unit/rules/formats/test_log_group_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0
"""

import pytest

from cfnlint.rules.formats.LogGroupName import LogGroupName


@pytest.fixture(scope="module")
def rule():
rule = LogGroupName()
yield rule


@pytest.mark.parametrize(
"name,instance,expected",
[
(
"Valid log group name",
"123457",
True,
),
(
"Valid with invalid type",
[],
True,
),
(
"Valid log group name with special characters",
"aws/one.two-three#four_five",
True,
),
("Invalid log group name because of special character", "foo&bar", False),
("Invalid log group name because of empty", "", False),
("Invalid log group name because too long", "a" * 513, False),
],
)
def test_validate(name, instance, expected, rule, validator):
result = rule.format(validator, instance)
assert result == expected, f"Test {name!r} got {result!r}"

0 comments on commit 08284a8

Please sign in to comment.