Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ _Example_:

For any change on `plugins/lookup/random.py`, this action will produce `lookup_random` and `test_random` as impacted targets.

## Relationship between extensions and targets

This action reads elements to test from `extensions` directory and corresponding tests from `tests/integration/targets` directory. Here after more details on the relationship between extensions and integration tests targets:

- `audit`, the test target name should have prefix `node_query_` or defines the `indirect_node_count` line into the `aliases` file, when `event_query.yml` file changed.

_Example_:

```
|___extensions/audit/event_query.yml
|___tests
|___integration
|___targets
|___node_query_database_cluster
|___query_instance_ec2
|___aliases (contains this line indirect_node_count)
```

For any change on `extensions/audit/event_query.yml` file, this action will produce `node_query_database_cluster` and `query_instance_ec2` as impacted targets.

## Debugging

- Set the label `test-all-the-targets` on the pull request to run the full test suite instead of the impacted changes.
Expand Down
23 changes: 23 additions & 0 deletions .github/actions/ansible_test_splitter/list_changed_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,14 @@ def plugin_utils(self) -> Generator[tuple[PosixPath, str], None, None]:
"""
yield from self._util_matches("plugins/plugin_utils/", "plugin_utils")

def extensions_audit_event_query(self) -> bool:
"""Return true when the extensions/audit/event_query.yml file has been updated"""
event_query_files = (
"extensions/audit/event_query.yml",
"extensions/audit/event_query.yaml",
)
return any([str(d) in event_query_files for d in self.changed_files()])


class Target:
"""A class to store information about a specific target."""
Expand Down Expand Up @@ -427,6 +435,21 @@ def add_target_to_plan(self, target_name: str) -> None:
if t.is_alias_of(target_name) and self.is_candidate_target(t):
self._my_test_plan.append(t)

def add_targets_to_plan_from_aliases_or_prefix_name(self, alias_line="", prefix_name=""):
"""Add targets to the plan from aliases line or prefix name."""
for t in self._targets():
if not self.is_candidate_target(t):
continue
# Add the target to the plan if either the name starts with `prefix_name` or
# The aliases file contains the line `alias_line`
if t.is_alias_of(alias_line) or t.name.startswith(prefix_name):
self._my_test_plan.append(t)

def add_indirect_node_count_targets_to_plan(self):
alias_line = "indirect_node_count"
prefix_name = "node_query_"
self.add_targets_to_plan_from_aliases_or_prefix_name(alias_line, prefix_name)

def cover_all(self) -> None:
"""Cover all the targets available."""
for cover_target in self.targets():
Expand Down
4 changes: 4 additions & 0 deletions .github/actions/ansible_test_splitter/list_changed_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def _add_changed_target(
_add_changed_target(whc.collection_name, target, "targets")
for role in whc.roles():
_add_changed_target(whc.collection_name, role, "roles")
# indirect node count targets
if whc.extensions_audit_event_query():
for collection in collections:
collection.add_indirect_node_count_targets_to_plan()

print("----------- Test plan -----------")
for collection in collections:
Expand Down