From d5ce6e6bed91aed3425062d9315f400d31881775 Mon Sep 17 00:00:00 2001 From: David Shrewsbury Date: Thu, 8 Apr 2021 15:24:01 -0400 Subject: [PATCH] Increase test coverage for command module (#74183) --- .../targets/command_shell/tasks/main.yml | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test/integration/targets/command_shell/tasks/main.yml b/test/integration/targets/command_shell/tasks/main.yml index 1b2644bff18..446832dd119 100644 --- a/test/integration/targets/command_shell/tasks/main.yml +++ b/test/integration/targets/command_shell/tasks/main.yml @@ -391,3 +391,65 @@ file: path: "{{ output_dir_test }}/afile.txt" state: absent + +- name: test warning with command + command: + cmd: "rm -h" + warn: yes + ignore_errors: yes + register: warn_result + +- name: assert warning exists + assert: + that: + - warn_result.warnings | length == 1 + - "'Consider using the file module with state=absent rather than running \\'rm\\'' in warn_result.warnings[0]" + +- name: test warning with shell + shell: "sed -h" + args: + warn: yes + ignore_errors: yes + register: warn_result + +- name: assert warning exists + assert: + that: + - warn_result.warnings | length == 1 + - "'Consider using the replace, lineinfile or template module rather than running \\'sed\\'' in warn_result.warnings[0]" + +- name: test become warning + command: + cmd: "sudo true" + warn: yes + ignore_errors: yes + register: warn_result + +- name: assert warning exists + assert: + that: + - warn_result.warnings | length == 1 + - "'Consider using \\'become\\', \\'become_method\\', and \\'become_user\\' rather than running sudo' in warn_result.warnings[0]" + +- name: test check mode skip message + command: + cmd: "true" + check_mode: yes + register: result + +- name: assert check message exists + assert: + that: + - "'skipped, running in check mode' in result.msg" + +- name: test check mode creates/removes message + command: + cmd: "true" + creates: yes + check_mode: yes + register: result + +- name: assert check message exists + assert: + that: + - "'Command would have run if not in check mode' in result.stdout"