diff --git a/test/integration/non_destructive.yml b/test/integration/non_destructive.yml index 519879940b..4c2178ca20 100644 --- a/test/integration/non_destructive.yml +++ b/test/integration/non_destructive.yml @@ -32,4 +32,4 @@ - { role: test_handlers, tags: test_handlers } - { role: test_lookups, tags: test_lookups } - { role: test_iterators, tags: test_iterators } - + - { role: test_command_shell, tags: test_command_shell } diff --git a/test/integration/roles/test_command_shell/files/create_afile.sh b/test/integration/roles/test_command_shell/files/create_afile.sh new file mode 100755 index 0000000000..e6fae448b2 --- /dev/null +++ b/test/integration/roles/test_command_shell/files/create_afile.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo "win" > "$1" \ No newline at end of file diff --git a/test/integration/roles/test_command_shell/files/remove_afile.sh b/test/integration/roles/test_command_shell/files/remove_afile.sh new file mode 100755 index 0000000000..4a7fea6617 --- /dev/null +++ b/test/integration/roles/test_command_shell/files/remove_afile.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +rm "$1" \ No newline at end of file diff --git a/test/integration/roles/test_command_shell/files/test.sh b/test/integration/roles/test_command_shell/files/test.sh old mode 100644 new mode 100755 diff --git a/test/integration/roles/test_command_shell/meta/main.yml b/test/integration/roles/test_command_shell/meta/main.yml new file mode 100644 index 0000000000..1050c23ce3 --- /dev/null +++ b/test/integration/roles/test_command_shell/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + diff --git a/test/integration/roles/test_command_shell/tasks/main.yml b/test/integration/roles/test_command_shell/tasks/main.yml new file mode 100644 index 0000000000..8e57f3fb93 --- /dev/null +++ b/test/integration/roles/test_command_shell/tasks/main.yml @@ -0,0 +1,170 @@ +# Test code for the command and shell modules. +# (c) 2014, Richard Isaacson + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +- set_fact: output_dir_test={{output_dir}}/test_command_shell + +- name: make sure our testing sub-directory does not exist + file: path="{{ output_dir_test }}" state=absent + +- name: create our testing sub-directory + file: path="{{ output_dir_test }}" state=directory + +- name: prep our test script + copy: src=test.sh dest="{{ output_dir_test }}" mode=0755 + +- name: prep our test script + copy: src=create_afile.sh dest="{{ output_dir_test }}" mode=0755 + +- name: prep our test script + copy: src=remove_afile.sh dest="{{ output_dir_test }}" mode=0755 + +## +## command +## + +- name: execute the test.sh script via command + command: "{{output_dir_test | expanduser}}/test.sh" + register: command_result0 + +- name: assert that the script executed correctly + assert: + that: + - "command_result0.rc == 0" + - "command_result0.stderr == ''" + - "command_result0.stdout == 'win'" + +# executable + +# FIXME doesn't have the expected stdout. + +#- name: execute the test.sh script with executable via command +# command: "{{output_dir_test | expanduser}}/test.sh executable=/bin/bash" +# register: command_result1 +# +#- name: assert that the script executed correctly with command +# assert: +# that: +# - "command_result1.rc == 0" +# - "command_result1.stderr == ''" +# - "command_result1.stdout == 'win'" + +# chdir + +- name: execute the test.sh script with chdir via command + command: ./test.sh chdir="{{output_dir_test | expanduser}}" + register: command_result2 + +- name: assert that the script executed correctly with chdir + assert: + that: + - "command_result2.rc == 0" + - "command_result2.stderr == ''" + - "command_result2.stdout == 'win'" + +# creates + +- name: verify that afile.txt is absent + 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" + +- name: verify that afile.txt is present + file: path={{output_dir_test}}/afile.txt state=file + +# 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" + +- 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 + assert: + that: + - "command_result3.changed != True" + +## +## shell +## + +- name: execute the test.sh script + shell: "{{output_dir_test | expanduser}}/test.sh" + register: shell_result0 + +- name: assert that the script executed correctly + assert: + that: + - "shell_result0.rc == 0" + - "shell_result0.stderr == ''" + - "shell_result0.stdout == 'win'" + +# executable + +# FIXME doesn't pass the expected stdout + +#- name: execute the test.sh script +# shell: "{{output_dir_test | expanduser}}/test.sh executable=/bin/bash" +# register: shell_result1 +# +#- name: assert that the shell executed correctly +# assert: +# that: +# - "shell_result1.rc == 0" +# - "shell_result1.stderr == ''" +# - "shell_result1.stdout == 'win'" + +# chdir + +- name: execute the test.sh script with chdir + shell: ./test.sh chdir="{{output_dir_test | expanduser}}" + register: shell_result2 + +- name: assert that the shell executed correctly with chdir + assert: + that: + - "shell_result2.rc == 0" + - "shell_result2.stderr == ''" + - "shell_result2.stdout == 'win'" + +# creates + +- name: verify that afile.txt is absent + file: path={{output_dir_test}}/afile.txt state=absent + +- name: execute the test.sh script with chdir + shell: "{{output_dir_test | expanduser}}/test.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 + +# removes + +- name: execute the test.sh script with chdir + shell: rm {{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 + register: shell_result4 + +- name: assert that the file was removed by the shell + assert: + that: + - "shell_result4.changed == False" \ No newline at end of file