Skip to content

Commit

Permalink
Merge pull request #1136 from moreati/fail_msg
Browse files Browse the repository at this point in the history
tests: Improve Ansible fail_msg formatting
  • Loading branch information
moreati authored Oct 6, 2024
2 parents 17d3f39 + 6accc87 commit de3c6dc
Show file tree
Hide file tree
Showing 96 changed files with 407 additions and 193 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Unreleased

* :gh:issue:`1106` :mod:`ansible_mitogen`: Support for `ansible_ssh_password`
connection variable, and templated SSH connection password.
* :gh:issue:`1136` tests: Improve Ansible fail_msg formatting.


v0.3.11 (2024-10-30)
Expand Down
3 changes: 2 additions & 1 deletion tests/ansible/integration/action/copy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
that:
- item.stat.checksum == item.item.expected_checksum
quiet: true # Avoid spamming stdout with 400 kB of item.item.content
fail_msg: item={{ item }}
fail_msg: |
item={{ item }}
with_items: "{{ stat.results }}"
loop_control:
label: "{{ item.stat.path }}"
Expand Down
15 changes: 10 additions & 5 deletions tests/ansible/integration/action/fixup_perms2__copy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
- assert:
that:
- out.stat.mode in ("0644", "0664")
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: "Copy files from content: arg"
copy:
Expand All @@ -29,7 +30,8 @@
- assert:
that:
- out.stat.mode == "0400"
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: Cleanup local weird mode file
file:
Expand All @@ -55,7 +57,8 @@
- assert:
that:
- out.stat.mode in ("0644", "0664")
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: Copy file with weird mode, preserving mode
copy:
Expand All @@ -69,7 +72,8 @@
- assert:
that:
- out.stat.mode == "1462"
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: Copy file with weird mode, explicit mode
copy:
Expand All @@ -84,7 +88,8 @@
- assert:
that:
- out.stat.mode == "1461"
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: Cleanup
file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
- 'raw.rc == 0'
- 'raw.stdout_lines[-1]|to_text == "2"'
- 'raw.stdout[-1]|to_text == "2"'
fail_msg: raw={{raw}}
fail_msg: |
raw={{ raw }}
- name: Run raw module with sudo
become: true
Expand All @@ -39,6 +40,7 @@
["root\r\n"],
["root"],
)
fail_msg: raw={{raw}}
fail_msg: |
raw={{ raw }}
tags:
- low_level_execute_command
25 changes: 18 additions & 7 deletions tests/ansible/integration/action/make_tmp_path.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@
assert:
that:
- good_temp_path == good_temp_path2
fail_msg: good_temp_path={{good_temp_path}} good_temp_path2={{good_temp_path2}}
fail_msg: |
good_temp_path={{ good_temp_path }}
good_temp_path2={{ good_temp_path2 }}
- name: "Verify different subdir for both tasks"
assert:
that:
- tmp_path.path != tmp_path2.path
fail_msg: tmp_path={{tmp_path}} tmp_path2={{tmp_path2}}
fail_msg: |
tmp_path={{ tmp_path }}
tmp_path2={{ tmp_path2 }}
#
# Verify subdirectory removal.
Expand All @@ -69,7 +73,9 @@
that:
- not stat1.stat.exists
- not stat2.stat.exists
fail_msg: stat1={{stat1}} stat2={{stat2}}
fail_msg: |
stat1={{ stat1 }}
stat2={{ stat2 }}
#
# Verify good directory persistence.
Expand All @@ -84,7 +90,8 @@
assert:
that:
- stat.stat.exists
fail_msg: stat={{stat}}
fail_msg: |
stat={{ stat }}
#
# Write some junk into the temp path.
Expand All @@ -107,7 +114,8 @@
- assert:
that:
- not out.stat.exists
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
#
# root
Expand All @@ -126,7 +134,9 @@
that:
- tmp_path2.path != tmp_path_root.path
- tmp_path2.path|dirname != tmp_path_root.path|dirname
fail_msg: tmp_path_root={{tmp_path_root}} tmp_path2={{tmp_path2}}
fail_msg: |
tmp_path_root={{ tmp_path_root }}
tmp_path2={{ tmp_path2 }}
#
# readonly homedir
Expand Down Expand Up @@ -157,7 +167,8 @@
that:
- out.module_path.startswith(good_temp_path2)
- out.module_tmpdir.startswith(good_temp_path2)
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
tags:
- make_tmp_path
- mitogen_only
18 changes: 12 additions & 6 deletions tests/ansible/integration/action/remote_expand_user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
register: out
- assert:
that: out.result == user_facts.ansible_facts.ansible_user_dir ~ '/foo'
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: "Expand ~/foo with become active. ~ is become_user's home."
action_passthrough:
Expand All @@ -49,7 +50,8 @@
register: out
- assert:
that: out.result == user_facts.ansible_facts.ansible_user_dir ~ '/foo'
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: "Expanding $HOME/foo has no effect."
action_passthrough:
Expand All @@ -60,7 +62,8 @@
register: out
- assert:
that: out.result == '$HOME/foo'
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
# ------------------------

Expand All @@ -73,7 +76,8 @@
register: out
- assert:
that: out.result == user_facts.ansible_facts.ansible_user_dir ~ '/foo'
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: "sudoable; Expand ~/foo with become active. ~ is become_user's home."
action_passthrough:
Expand All @@ -97,7 +101,8 @@
register: out
- assert:
that: out.result == user_facts.ansible_facts.ansible_user_dir ~ '/foo'
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: "sudoable; Expanding $HOME/foo has no effect."
action_passthrough:
Expand All @@ -108,6 +113,7 @@
register: out
- assert:
that: out.result == '$HOME/foo'
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
tags:
- remote_expand_user
6 changes: 4 additions & 2 deletions tests/ansible/integration/action/remote_file_exists.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
register: out
- assert:
that: out.result == False
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: Ensure does-exist does
copy:
Expand All @@ -24,7 +25,8 @@
register: out
- assert:
that: out.result == True
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: Cleanup
file:
Expand Down
6 changes: 4 additions & 2 deletions tests/ansible/integration/action/remove_tmp_path.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
- assert:
that:
- not out2.stat.exists
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- stat:
path: "{{out.src|dirname}}"
Expand All @@ -32,7 +33,8 @@
- assert:
that:
- not out2.stat.exists
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- file:
path: /tmp/remove_tmp_path_test
Expand Down
3 changes: 2 additions & 1 deletion tests/ansible/integration/action/synchronize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@

- assert:
that: outout == "item!"
fail_msg: outout={{outout}}
fail_msg: |
outout={{ outout }}
when: False

# TODO: https://github.com/dw/mitogen/issues/692
Expand Down
6 changes: 4 additions & 2 deletions tests/ansible/integration/action/transfer_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
- assert:
that: |
out.content|b64decode == '{"I am JSON": true}'
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: Create text transfer data
action_passthrough:
Expand All @@ -37,7 +38,8 @@
- assert:
that:
out.content|b64decode == 'I am text.'
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: Cleanup transfer data
file:
Expand Down
3 changes: 2 additions & 1 deletion tests/ansible/integration/async/multiple_items_loop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- out.results[1].stdout == 'hi-from-job-2'
- out.results[1].rc == 0
- out.results[1].delta > '0:00:05'
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
tags:
- multiple_items_loop
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
(job.started == 1) and
(job.changed == True) and
(job.finished == 0)
fail_msg: job={{job}}
fail_msg: |
job={{ job }}
- name: busy-poll up to 100000 times
async_status:
Expand All @@ -52,7 +53,8 @@
- async_out.failed == False
- async_out.msg == "Hello, world."
- 'async_out.stderr == "binary_producing_json: oh noes\n"'
fail_msg: async_out={{async_out}}
fail_msg: |
async_out={{ async_out }}
vars:
async_out: "{{result.content|b64decode|from_json}}"
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
- async_out.msg.startswith("Traceback")
- '"ValueError: No start of json char found\n" in async_out.msg'
- 'async_out.stderr == "binary_producing_junk: oh noes\n"'
fail_msg: async_out={{async_out}}
fail_msg: |
async_out={{ async_out }}
vars:
async_out: "{{result.content|b64decode|from_json}}"
tags:
Expand Down
6 changes: 4 additions & 2 deletions tests/ansible/integration/async/result_shell_echo_hi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@
- async_out.start.startswith("20")
- async_out.stderr == "there"
- async_out.stdout == "hi"
fail_msg: async_out={{async_out}}
fail_msg: |
async_out={{ async_out }}
vars:
async_out: "{{result.content|b64decode|from_json}}"

- assert:
that:
- async_out.invocation.module_args.stdin == None
fail_msg: async_out={{async_out}}
fail_msg: |
async_out={{ async_out }}
when:
- ansible_version.full is version('2.4', '>=', strict=True)
vars:
Expand Down
8 changes: 6 additions & 2 deletions tests/ansible/integration/async/runner_new_process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
- assert:
that:
- sync_proc1.pid == sync_proc2.pid
fail_msg: sync_proc1={{sync_proc1}} sync_proc2={{sync_proc2}}
fail_msg: |
sync_proc1={{ sync_proc1 }}
sync_proc2={{ sync_proc2 }}
when: is_mitogen

- name: get async process ID.
Expand Down Expand Up @@ -52,7 +54,9 @@
- sync_proc1.pid == sync_proc2.pid
- async_result1.pid != sync_proc1.pid
- async_result1.pid != async_result2.pid
fail_msg: async_result1={{async_result1}} async_result2={{async_result2}}
fail_msg: |
async_result1={{ async_result1 }}
async_result2={{ async_result2 }}
when: is_mitogen
tags:
- runner_new_process
Loading

0 comments on commit de3c6dc

Please sign in to comment.