Handle non-target file deps for integration tests.

Some integration test targets have dependencies on files outside
the `test/integration/targets/` directory tree. Changes to these
dependencies can result in unexpected test failures since they do
not trigger integration tests which depend on them.
This commit is contained in:
Matt Clay 2019-01-12 00:18:17 -08:00
parent 3db6b9b416
commit 6a0452559b
7 changed files with 53 additions and 0 deletions

View file

@ -1,2 +1,3 @@
shippable/cloud/group1
cloud/foreman
needs/file/contrib/inventory/foreman.py

View file

@ -1,3 +1,4 @@
shippable/posix/group2
destructive
needs/target/setup_openssl
needs/file/test/runner/requirements/constraints.txt

View file

@ -0,0 +1 @@
needs/file/test/runner/requirements/constraints.txt

View file

@ -1 +1,3 @@
shippable/posix/group3
needs/file/hacking/test-module
needs/file/lib/ansible/modules/system/ping.py

View file

@ -1,3 +1,4 @@
destructive
shippable/posix/group1
needs/httptester
needs/file/test/runner/requirements/constraints.txt

View file

@ -196,7 +196,49 @@ class PathMapper(object):
self.powershell_module_utils_imports = {} # populated on first use to reduce overhead when not needed
self.csharp_module_utils_imports = {} # populated on first use to reduce overhead when not needed
self.paths_to_dependent_targets = {}
for target in self.integration_targets:
for path in target.needs_file:
if path not in self.paths_to_dependent_targets:
self.paths_to_dependent_targets[path] = set()
self.paths_to_dependent_targets[path].add(target)
def get_dependent_paths(self, path):
"""
:type path: str
:rtype: list[str]
"""
unprocessed_paths = set(self.get_dependent_paths_non_recursive(path))
paths = set()
while unprocessed_paths:
queued_paths = list(unprocessed_paths)
paths |= unprocessed_paths
unprocessed_paths = set()
for queued_path in queued_paths:
new_paths = self.get_dependent_paths_non_recursive(queued_path)
for new_path in new_paths:
if new_path not in paths:
unprocessed_paths.add(new_path)
return sorted(paths)
def get_dependent_paths_non_recursive(self, path):
"""
:type path: str
:rtype: list[str]
"""
paths = self.get_dependent_paths_internal(path)
paths += [t.path + '/' for t in self.paths_to_dependent_targets.get(path, set())]
paths = sorted(set(paths))
return paths
def get_dependent_paths_internal(self, path):
"""
:type path: str
:rtype: list[str]

View file

@ -626,6 +626,11 @@ class IntegrationTarget(CompletionTarget):
if self.type not in ('script', 'role'):
groups.append('hidden')
# Collect file paths before group expansion to avoid including the directories.
# Ignore references to test targets, as those must be defined using `needs/target/*` or other target references.
self.needs_file = tuple(sorted(set('/'.join(g.split('/')[2:]) for g in groups if
g.startswith('needs/file/') and not g.startswith('needs/file/test/integration/targets/'))))
for group in itertools.islice(groups, 0, len(groups)):
if '/' in group:
parts = group.split('/')