From 58355ad03e4fb59fdab078e2893682f6c70a738a Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Fri, 8 Dec 2023 12:32:16 +0000 Subject: [PATCH] Refactor callbacks tests to allow multiple test cases --- .../callbacks_list.expected | 0 .../all-callbacks/env-vars | 1 + .../{ => all-callbacks}/include_me.yml | 0 .../test.yml} | 0 .../callbacks_list.expected} | 0 .../include_role-fail-free/env-vars | 1 + .../test.yml} | 0 .../callbacks_list.expected | 9 ++++++++ .../include_role-fail-linear/env-vars | 1 + .../include_role-fail-linear/test.yml | 5 +++++ .../ansible-playbook-callbacks/runme.sh | 22 ++++++++++++------- 11 files changed, 31 insertions(+), 8 deletions(-) rename test/integration/targets/ansible-playbook-callbacks/{ => all-callbacks}/callbacks_list.expected (100%) create mode 100644 test/integration/targets/ansible-playbook-callbacks/all-callbacks/env-vars rename test/integration/targets/ansible-playbook-callbacks/{ => all-callbacks}/include_me.yml (100%) rename test/integration/targets/ansible-playbook-callbacks/{all-callbacks.yml => all-callbacks/test.yml} (100%) rename test/integration/targets/ansible-playbook-callbacks/{callback_list_include_role_fail.expected => include_role-fail-free/callbacks_list.expected} (100%) create mode 100644 test/integration/targets/ansible-playbook-callbacks/include_role-fail-free/env-vars rename test/integration/targets/ansible-playbook-callbacks/{include_role-fail.yml => include_role-fail-free/test.yml} (100%) create mode 100644 test/integration/targets/ansible-playbook-callbacks/include_role-fail-linear/callbacks_list.expected create mode 100644 test/integration/targets/ansible-playbook-callbacks/include_role-fail-linear/env-vars create mode 100644 test/integration/targets/ansible-playbook-callbacks/include_role-fail-linear/test.yml diff --git a/test/integration/targets/ansible-playbook-callbacks/callbacks_list.expected b/test/integration/targets/ansible-playbook-callbacks/all-callbacks/callbacks_list.expected similarity index 100% rename from test/integration/targets/ansible-playbook-callbacks/callbacks_list.expected rename to test/integration/targets/ansible-playbook-callbacks/all-callbacks/callbacks_list.expected diff --git a/test/integration/targets/ansible-playbook-callbacks/all-callbacks/env-vars b/test/integration/targets/ansible-playbook-callbacks/all-callbacks/env-vars new file mode 100644 index 00000000000..7dfd40bdf97 --- /dev/null +++ b/test/integration/targets/ansible-playbook-callbacks/all-callbacks/env-vars @@ -0,0 +1 @@ +export ANSIBLE_HOST_PATTERN_MISMATCH=warning diff --git a/test/integration/targets/ansible-playbook-callbacks/include_me.yml b/test/integration/targets/ansible-playbook-callbacks/all-callbacks/include_me.yml similarity index 100% rename from test/integration/targets/ansible-playbook-callbacks/include_me.yml rename to test/integration/targets/ansible-playbook-callbacks/all-callbacks/include_me.yml diff --git a/test/integration/targets/ansible-playbook-callbacks/all-callbacks.yml b/test/integration/targets/ansible-playbook-callbacks/all-callbacks/test.yml similarity index 100% rename from test/integration/targets/ansible-playbook-callbacks/all-callbacks.yml rename to test/integration/targets/ansible-playbook-callbacks/all-callbacks/test.yml diff --git a/test/integration/targets/ansible-playbook-callbacks/callback_list_include_role_fail.expected b/test/integration/targets/ansible-playbook-callbacks/include_role-fail-free/callbacks_list.expected similarity index 100% rename from test/integration/targets/ansible-playbook-callbacks/callback_list_include_role_fail.expected rename to test/integration/targets/ansible-playbook-callbacks/include_role-fail-free/callbacks_list.expected diff --git a/test/integration/targets/ansible-playbook-callbacks/include_role-fail-free/env-vars b/test/integration/targets/ansible-playbook-callbacks/include_role-fail-free/env-vars new file mode 100644 index 00000000000..695f62abb50 --- /dev/null +++ b/test/integration/targets/ansible-playbook-callbacks/include_role-fail-free/env-vars @@ -0,0 +1 @@ +export ANSIBLE_STRATEGY=free diff --git a/test/integration/targets/ansible-playbook-callbacks/include_role-fail.yml b/test/integration/targets/ansible-playbook-callbacks/include_role-fail-free/test.yml similarity index 100% rename from test/integration/targets/ansible-playbook-callbacks/include_role-fail.yml rename to test/integration/targets/ansible-playbook-callbacks/include_role-fail-free/test.yml diff --git a/test/integration/targets/ansible-playbook-callbacks/include_role-fail-linear/callbacks_list.expected b/test/integration/targets/ansible-playbook-callbacks/include_role-fail-linear/callbacks_list.expected new file mode 100644 index 00000000000..ea2f4fe4e09 --- /dev/null +++ b/test/integration/targets/ansible-playbook-callbacks/include_role-fail-linear/callbacks_list.expected @@ -0,0 +1,9 @@ +1 __init__ +7 v2_on_any +1 v2_playbook_on_play_start +1 v2_playbook_on_start +1 v2_playbook_on_stats +1 v2_playbook_on_task_start +1 v2_runner_on_failed +1 v2_runner_on_ok +1 v2_runner_on_start diff --git a/test/integration/targets/ansible-playbook-callbacks/include_role-fail-linear/env-vars b/test/integration/targets/ansible-playbook-callbacks/include_role-fail-linear/env-vars new file mode 100644 index 00000000000..302680f6875 --- /dev/null +++ b/test/integration/targets/ansible-playbook-callbacks/include_role-fail-linear/env-vars @@ -0,0 +1 @@ +export ANSIBLE_STRATEGY=linear diff --git a/test/integration/targets/ansible-playbook-callbacks/include_role-fail-linear/test.yml b/test/integration/targets/ansible-playbook-callbacks/include_role-fail-linear/test.yml new file mode 100644 index 00000000000..fbfeb465af9 --- /dev/null +++ b/test/integration/targets/ansible-playbook-callbacks/include_role-fail-linear/test.yml @@ -0,0 +1,5 @@ +- hosts: localhost + gather_facts: false + tasks: + - include_role: + name: does-not-exist diff --git a/test/integration/targets/ansible-playbook-callbacks/runme.sh b/test/integration/targets/ansible-playbook-callbacks/runme.sh index 77a5d9b70ac..e6e36d04592 100755 --- a/test/integration/targets/ansible-playbook-callbacks/runme.sh +++ b/test/integration/targets/ansible-playbook-callbacks/runme.sh @@ -2,14 +2,20 @@ set -eux -export ANSIBLE_CALLBACK_PLUGINS=../support-callback_plugins/callback_plugins -export ANSIBLE_ROLES_PATH=../ +export ANSIBLE_CALLBACK_PLUGINS=../../support-callback_plugins/callback_plugins +export ANSIBLE_ROLES_PATH=../../ export ANSIBLE_STDOUT_CALLBACK=callback_debug -ANSIBLE_HOST_PATTERN_MISMATCH=warning ansible-playbook all-callbacks.yml 2>/dev/null | sort | uniq -c | tee callbacks_list.out -diff -w callbacks_list.out callbacks_list.expected - -for strategy in linear free; do - ANSIBLE_STRATEGY=$strategy ansible-playbook include_role-fail.yml 2>/dev/null | sort | uniq -c | tee callback_list_include_role_fail.out - diff -w callback_list_include_role_fail.out callback_list_include_role_fail.expected +for testcase in */; do + echo "Testing $testcase" + pushd "$testcase" + # Execute in a subshell to isolate environment variables + ( + if [[ -f env-vars ]]; then + source env-vars + fi + ansible-playbook test.yml 2>/dev/null | sort | uniq -c | tee callbacks_list.out + ) + diff -w callbacks_list.out callbacks_list.expected + popd done