-
Notifications
You must be signed in to change notification settings - Fork 24k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fixes the coverage path translation for modules located in integration test paths. Instead of trying to match by the unique temporary path name that the module is executed as, the reporting tool will translate it to the static path that the module is actually located under. (cherry picked from commit f9b58fa)
- Loading branch information
Showing
9 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
bugfixes: | ||
- >- | ||
ansible-test - Fix up coverage reporting to properly translate the temporary path of integration test modules to | ||
the expected static test module path. |
3 changes: 3 additions & 0 deletions
3
test/integration/targets/ansible-test-coverage-windows/aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
shippable/windows/group1 | ||
windows | ||
needs/target/collection |
6 changes: 6 additions & 0 deletions
6
...sible-test-coverage-windows/ansible_collections/ns/col/plugins/modules/win_collection.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!powershell | ||
|
||
#AnsibleRequires -CSharpUtil Ansible.Basic | ||
|
||
$module = [Ansible.Basic.AnsibleModule]::Create($args, @{}) | ||
$module.ExitJson() |
6 changes: 6 additions & 0 deletions
6
...llections/ns/col/tests/integration/targets/win_collection/library/test_win_collection.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!powershell | ||
|
||
#AnsibleRequires -CSharpUtil Ansible.Basic | ||
|
||
$module = [Ansible.Basic.AnsibleModule]::Create($args, @{}) | ||
$module.ExitJson() |
5 changes: 5 additions & 0 deletions
5
...indows/ansible_collections/ns/col/tests/integration/targets/win_collection/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- name: run module in collection to test coverage for collection plugins | ||
win_collection: | ||
|
||
- name: run module in library adjacent to test coverage for test plugins | ||
test_win_collection: |
20 changes: 20 additions & 0 deletions
20
test/integration/targets/ansible-test-coverage-windows/runme.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
TEST_PATH="${PWD}/test-coverage.py" | ||
|
||
source ../collection/setup.sh | ||
cp "${INVENTORY_PATH}" tests/integration/inventory.winrm | ||
|
||
set -x | ||
|
||
# common args for all tests | ||
common=(--venv --color --truncate 0 "${@}") | ||
|
||
# run command that generates coverage data for Windows | ||
ansible-test windows-integration win_collection "${common[@]}" --coverage | ||
|
||
# report on code coverage in all supported formats | ||
ansible-test coverage report "${common[@]}" | ||
|
||
# test we covered the 2 files we expect to have been covered and their lines | ||
python "${TEST_PATH}" |
27 changes: 27 additions & 0 deletions
27
test/integration/targets/ansible-test-coverage-windows/test-coverage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
import os | ||
import os.path | ||
|
||
|
||
def main() -> None: | ||
collection_root = os.getcwd() | ||
print(f"Running windows-integration coverage test in '{collection_root}'") | ||
|
||
result_path = os.path.join(collection_root, "tests", "output", "coverage", "coverage-powershell") | ||
module_path = os.path.join(collection_root, "plugins", "modules", "win_collection.ps1") | ||
test_path = os.path.join(collection_root, "tests", "integration", "targets", "win_collection", "library", "test_win_collection.ps1") | ||
with open(result_path, mode="rb") as fd: | ||
data = json.load(fd) | ||
|
||
for path, result in data.items(): | ||
print(f"Testing result for path '{path}' -> {result!r}") | ||
assert path in [module_path, test_path], f"Found unexpected coverage result path '{path}'" | ||
assert result == {'5': 1, '6': 1}, "Coverage result did not pick up a hit on lines 5 and 6" | ||
|
||
assert len(data) == 2, f"Expected coverage results for 2 files but got {len(data)}" | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters