mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 05:40:23 -07:00
Split integration tests out from Makefile. (#17976)
This commit is contained in:
parent
bf3d546d9a
commit
80a5c70ad7
169 changed files with 612 additions and 420 deletions
2
test/integration/targets/blocks/fail.yml
Normal file
2
test/integration/targets/blocks/fail.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
- name: EXPECTED FAILURE
|
||||
fail: msg="{{msg}}"
|
103
test/integration/targets/blocks/main.yml
Normal file
103
test/integration/targets/blocks/main.yml
Normal file
|
@ -0,0 +1,103 @@
|
|||
- name: simple block test
|
||||
hosts: localhost
|
||||
gather_facts: yes
|
||||
strategy: "{{test_strategy|default('linear')}}"
|
||||
vars:
|
||||
block_tasks_run: false
|
||||
block_rescue_run: false
|
||||
block_always_run: false
|
||||
nested_block_always_run: false
|
||||
tasks_run_after_failure: false
|
||||
rescue_run_after_failure: false
|
||||
always_run_after_failure: false
|
||||
tasks:
|
||||
- block:
|
||||
- name: set block tasks run flag
|
||||
set_fact:
|
||||
block_tasks_run: true
|
||||
- name: EXPECTED FAILURE fail in tasks
|
||||
fail:
|
||||
- name: tasks flag should not be set after failure
|
||||
set_fact:
|
||||
tasks_run_after_failure: true
|
||||
rescue:
|
||||
- name: set block rescue run flag
|
||||
set_fact:
|
||||
block_rescue_run: true
|
||||
- name: EXPECTED FAILURE fail in rescue
|
||||
fail:
|
||||
- name: tasks flag should not be set after failure in rescue
|
||||
set_fact:
|
||||
rescue_run_after_failure: true
|
||||
always:
|
||||
- name: set block always run flag
|
||||
set_fact:
|
||||
block_always_run: true
|
||||
#- block:
|
||||
# - meta: noop
|
||||
# always:
|
||||
# - name: set nested block always run flag
|
||||
# set_fact:
|
||||
# nested_block_always_run: true
|
||||
# - name: fail in always
|
||||
# fail:
|
||||
# - name: tasks flag should not be set after failure in always
|
||||
# set_fact:
|
||||
# always_run_after_failure: true
|
||||
- meta: clear_host_errors
|
||||
|
||||
post_tasks:
|
||||
- assert:
|
||||
that:
|
||||
- block_tasks_run
|
||||
- block_rescue_run
|
||||
- block_always_run
|
||||
#- nested_block_always_run
|
||||
- not tasks_run_after_failure
|
||||
- not rescue_run_after_failure
|
||||
- not always_run_after_failure
|
||||
- debug: msg="TEST COMPLETE"
|
||||
|
||||
- name: block with includes
|
||||
hosts: localhost
|
||||
gather_facts: yes
|
||||
strategy: "{{test_strategy|default('linear')}}"
|
||||
vars:
|
||||
rescue_run_after_include_fail: false
|
||||
always_run_after_include_fail_in_rescue: false
|
||||
tasks_run_after_failure: false
|
||||
rescue_run_after_failure: false
|
||||
always_run_after_failure: false
|
||||
tasks:
|
||||
- block:
|
||||
- name: include fail.yml in tasks
|
||||
include: fail.yml
|
||||
args:
|
||||
msg: "failed from tasks"
|
||||
- name: tasks flag should not be set after failure
|
||||
set_fact:
|
||||
tasks_run_after_failure: true
|
||||
rescue:
|
||||
- set_fact:
|
||||
rescue_run_after_include_fail: true
|
||||
- name: include fail.yml in rescue
|
||||
include: fail.yml
|
||||
args:
|
||||
msg: "failed from rescue"
|
||||
- name: flag should not be set after failure in rescue
|
||||
set_fact:
|
||||
rescue_run_after_failure: true
|
||||
always:
|
||||
- set_fact:
|
||||
always_run_after_include_fail_in_rescue: true
|
||||
- meta: clear_host_errors
|
||||
|
||||
post_tasks:
|
||||
- assert:
|
||||
that:
|
||||
- rescue_run_after_include_fail
|
||||
- always_run_after_include_fail_in_rescue
|
||||
- not tasks_run_after_failure
|
||||
- not rescue_run_after_failure
|
||||
- not always_run_after_failure
|
||||
- debug: msg="TEST COMPLETE"
|
3
test/integration/targets/blocks/nested_fail.yml
Normal file
3
test/integration/targets/blocks/nested_fail.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
- include: fail.yml
|
||||
args:
|
||||
msg: "nested {{msg}}"
|
3
test/integration/targets/blocks/nested_nested_fail.yml
Normal file
3
test/integration/targets/blocks/nested_nested_fail.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
- include: nested_fail.yml
|
||||
args:
|
||||
msg: "nested {{msg}}"
|
20
test/integration/targets/blocks/runme.sh
Executable file
20
test/integration/targets/blocks/runme.sh
Executable file
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -eux
|
||||
|
||||
# remove old output log
|
||||
rm -f block_test.out
|
||||
# run the test and check to make sure the right number of completions was logged
|
||||
ansible-playbook -vv main.yml -i ../../inventory "$@" | tee block_test.out
|
||||
env python -c \
|
||||
'import sys, re; sys.stdout.write(re.sub("\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]", "", sys.stdin.read()))' \
|
||||
<block_test.out >block_test_wo_colors.out
|
||||
[ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(egrep '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ]
|
||||
# cleanup the output log again, to make sure the test is clean
|
||||
rm -f block_test.out block_test_wo_colors.out
|
||||
# run test with free strategy and again count the completions
|
||||
ansible-playbook -vv main.yml -i ../../inventory -e test_strategy=free "$@" | tee block_test.out
|
||||
env python -c \
|
||||
'import sys, re; sys.stdout.write(re.sub("\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]", "", sys.stdin.read()))' \
|
||||
<block_test.out >block_test_wo_colors.out
|
||||
[ "$(grep -c 'TEST COMPLETE' block_test.out)" = "$(egrep '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ]
|
Loading…
Add table
Add a link
Reference in a new issue