mirror of https://github.com/ansible/ansible.git
ansible-test - fix coverage for test modules
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.pull/84366/head
parent
2a53b851fe
commit
4e7403e5d3
@ -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.
|
@ -0,0 +1,3 @@
|
||||
shippable/windows/group1
|
||||
windows
|
||||
needs/target/collection
|
@ -0,0 +1,6 @@
|
||||
#!powershell
|
||||
|
||||
#AnsibleRequires -CSharpUtil Ansible.Basic
|
||||
|
||||
$module = [Ansible.Basic.AnsibleModule]::Create($args, @{})
|
||||
$module.ExitJson()
|
@ -0,0 +1,6 @@
|
||||
#!powershell
|
||||
|
||||
#AnsibleRequires -CSharpUtil Ansible.Basic
|
||||
|
||||
$module = [Ansible.Basic.AnsibleModule]::Create($args, @{})
|
||||
$module.ExitJson()
|
@ -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:
|
@ -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}"
|
@ -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()
|
Loading…
Reference in New Issue