Skip to content

Commit 4eb28d5

Browse files
committed
Execute resources tests on cloudformation changes
1 parent 46d2212 commit 4eb28d5

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

localstack-core/localstack/testing/testselection/matching.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fnmatch
2+
import glob
23
import pathlib
34
import re
45
from collections import defaultdict
@@ -162,6 +163,32 @@ def generic_service_test_matching_rule(
162163
return set()
163164

164165

166+
def cloudformation_resource_provider_rule(
167+
changed_file_path: str,
168+
search_patterns: Iterable[str] = DEFAULT_SEARCH_PATTERNS,
169+
test_dirs: Iterable[str] = ("tests/aws/services",),
170+
) -> Iterable[str]:
171+
root_dir = (pathlib.Path.cwd() / ".." / ".." / ".." / "..").resolve()
172+
match = None
173+
for pattern in search_patterns:
174+
match = re.findall(pattern, changed_file_path)
175+
if match:
176+
break
177+
178+
if match:
179+
changed_service = match[0]
180+
if changed_service != "cloudformation":
181+
return []
182+
183+
out = set()
184+
for test_dir in test_dirs:
185+
resources_dirs = list(glob.iglob(f"{root_dir / test_dir}/*/resources"))
186+
for resource_dir in resources_dirs:
187+
out.add(str(pathlib.Path(resource_dir).relative_to(root_dir)))
188+
189+
return out
190+
191+
165192
MatchingRule = Callable[[str], Iterable[str]]
166193

167194

@@ -206,4 +233,6 @@ def check_rule_has_matches(rule: MatchingRule, files: Iterable[str]) -> bool:
206233
Matchers.glob(".git-blame-ignore-revs").ignore(),
207234
# lambda
208235
Matchers.glob("tests/aws/services/lambda_/functions/**").service_tests(services=["lambda"]),
236+
# CloudFormation
237+
cloudformation_resource_provider_rule,
209238
]

tests/unit/testing/testselection/test_matching.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,9 @@ def test_directory_rules_no_match():
140140
assert selected_tests == [SENTINEL_ALL_TESTS]
141141

142142

143-
def test_cloudformation_tests_executed_on_service_changes():
144-
selected_tests = get_affected_tests_from_changes(
145-
["localstack/services/lambda_/provider.py"], MATCHING_RULES
146-
)
147-
assert selected_tests == []
148-
149-
150143
def test_service_tests_executed_on_cloudformation_changes():
151144
selected_tests = get_affected_tests_from_changes(
152145
["localstack/services/cloudformation/provider.py"], MATCHING_RULES
153146
)
154-
assert "tests/aws/services/lambda_/resource_providers/" in selected_tests
147+
# picking lambda as an example
148+
assert "tests/aws/services/lambda_/resources" in selected_tests

0 commit comments

Comments
 (0)