From fce04b1eba5343f0b23c50af24404a2826591345 Mon Sep 17 00:00:00 2001 From: "Federico G. Schwindt" Date: Sun, 14 Dec 2014 22:39:17 +0000 Subject: [PATCH 1/2] Use command= when we intended to While here sort register variables and add a comment to signal multiline testing. --- .../roles/test_command_shell/tasks/main.yml | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/test/integration/roles/test_command_shell/tasks/main.yml b/test/integration/roles/test_command_shell/tasks/main.yml index b331452b7c6..877eb11cd6d 100644 --- a/test/integration/roles/test_command_shell/tasks/main.yml +++ b/test/integration/roles/test_command_shell/tasks/main.yml @@ -82,7 +82,7 @@ file: path={{output_dir_test}}/afile.txt state=absent - name: create afile.txt with create_afile.sh via command - shell: "{{output_dir_test | expanduser}}/create_afile.sh {{output_dir_test | expanduser}}/afile.txt creates={{output_dir_test | expanduser}}/afile.txt" + command: "{{output_dir_test | expanduser}}/create_afile.sh {{output_dir_test | expanduser}}/afile.txt creates={{output_dir_test | expanduser}}/afile.txt" - name: verify that afile.txt is present file: path={{output_dir_test}}/afile.txt state=file @@ -90,7 +90,7 @@ # removes - name: remove afile.txt with remote_afile.sh via command - shell: "{{output_dir_test | expanduser}}/remove_afile.sh {{output_dir_test | expanduser}}/afile.txt removes={{output_dir_test | expanduser}}/afile.txt" + command: "{{output_dir_test | expanduser}}/remove_afile.sh {{output_dir_test | expanduser}}/afile.txt removes={{output_dir_test | expanduser}}/afile.txt" - name: verify that afile.txt is absent file: path={{output_dir_test}}/afile.txt state=absent @@ -161,21 +161,23 @@ - name: remove afile.txt using rm shell: rm {{output_dir_test | expanduser}}/afile.txt removes={{output_dir_test | expanduser}}/afile.txt - register: shell_result4 + register: shell_result3 - name: assert that using rm under shell causes a warning assert: that: - - "shell_result4.warnings" + - "shell_result3.warnings" - name: verify that afile.txt is absent file: path={{output_dir_test}}/afile.txt state=absent - register: shell_result5 + register: shell_result4 - name: assert that the file was removed by the shell assert: that: - - "shell_result5.changed == False" + - "shell_result4.changed == False" + +# multiline - name: execute a shell command using a literal multiline block args: @@ -189,28 +191,28 @@ | tr -s ' ' \ | cut -f1 -d ' ' echo "this is a second line" - register: shell_result6 + register: shell_result5 -- debug: var=shell_result6 +- debug: var=shell_result5 - name: assert the multiline shell command ran as expected assert: that: - - "shell_result6.changed" - - "shell_result6.stdout == '5575bb6b71c9558db0b6fbbf2f19909eeb4e3b98\nthis is a second line'" + - "shell_result5.changed" + - "shell_result5.stdout == '5575bb6b71c9558db0b6fbbf2f19909eeb4e3b98\nthis is a second line'" - name: execute a shell command using a literal multiline block with arguments in it shell: | executable=/bin/bash creates={{output_dir_test | expanduser}}/afile.txt echo "test" - register: shell_result7 + register: shell_result6 - name: assert the multiline shell command with arguments in it run as expected assert: that: - - "shell_result7.changed" - - "shell_result7.stdout == 'test'" + - "shell_result6.changed" + - "shell_result6.stdout == 'test'" - name: remove the previously created file file: path={{output_dir_test}}/afile.txt state=absent From 91a73cff81476873d73f112406a1c6dae6793c6f Mon Sep 17 00:00:00 2001 From: "Federico G. Schwindt" Date: Sun, 14 Dec 2014 22:40:04 +0000 Subject: [PATCH 2/2] Add tests for globbing support --- .../roles/test_command_shell/tasks/main.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/integration/roles/test_command_shell/tasks/main.yml b/test/integration/roles/test_command_shell/tasks/main.yml index 877eb11cd6d..325e76cffea 100644 --- a/test/integration/roles/test_command_shell/tasks/main.yml +++ b/test/integration/roles/test_command_shell/tasks/main.yml @@ -87,6 +87,15 @@ - name: verify that afile.txt is present file: path={{output_dir_test}}/afile.txt state=file +- name: re-run previous command using creates with globbing + command: "{{output_dir_test | expanduser}}/create_afile.sh {{output_dir_test | expanduser}}/afile.txt creates={{output_dir_test | expanduser}}/afile.*" + register: command_result3 + +- name: assert that creates with globbing is working + assert: + that: + - "command_result3.changed != True" + # removes - name: remove afile.txt with remote_afile.sh via command @@ -94,12 +103,15 @@ - name: verify that afile.txt is absent file: path={{output_dir_test}}/afile.txt state=absent - register: command_result3 -- name: assert that the file was removed by the script +- name: re-run previous command using removes with globbing + command: "{{output_dir_test | expanduser}}/remove_afile.sh {{output_dir_test | expanduser}}/afile.txt removes={{output_dir_test | expanduser}}/afile.*" + register: command_result4 + +- name: assert that removes with globbing is working assert: that: - - "command_result3.changed != True" + - "command_result4.changed != True" ## ## shell