Skip to content

Commit 773ac7c

Browse files
authored
Add test for changelog entry validation (#4776)
1 parent 3c7e487 commit 773ac7c

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

tests/unit/test_changelog.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
import json
4+
from pathlib import Path
5+
6+
import pytest
7+
8+
REPO_ROOT = Path(__file__).parents[2]
9+
NEXT_RELEASE_DIR = REPO_ROOT / '.changes' / 'next-release'
10+
11+
12+
def _next_release_json_files():
13+
if not NEXT_RELEASE_DIR.is_dir():
14+
return []
15+
return [
16+
p for p in sorted(NEXT_RELEASE_DIR.iterdir()) if p.suffix == '.json'
17+
]
18+
19+
20+
@pytest.mark.parametrize(
21+
"json_path",
22+
_next_release_json_files(),
23+
ids=lambda p: p.name,
24+
)
25+
def test_next_release_json_is_well_formed(json_path):
26+
raw = json_path.read_text('utf-8')
27+
try:
28+
entry = json.loads(raw)
29+
except json.JSONDecodeError as e:
30+
pytest.fail(f"{json_path.name} is not valid JSON: {e}")
31+
assert isinstance(entry, dict), (
32+
f"{json_path.name} should be a JSON object, got {type(entry).__name__}"
33+
)
34+
VALID_TYPES = {'feature', 'bugfix', 'enhancement', 'api-change'}
35+
for key in ('category', 'description', 'type'):
36+
assert key in entry, f"{json_path.name} missing required key '{key}'"
37+
assert isinstance(entry[key], str) and entry[key].strip(), (
38+
f"{json_path.name} key '{key}' must be a non-empty string"
39+
)
40+
assert entry['type'] in VALID_TYPES, (
41+
f"{json_path.name} has invalid type '{entry['type']}', "
42+
f"must be one of {sorted(VALID_TYPES)}"
43+
)

0 commit comments

Comments
 (0)