From 04bd6a3619c84d39faa220893dab5266f32665ce Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Fri, 19 Aug 2016 10:23:14 -0700 Subject: [PATCH] Make tests more cross platform. (#17154) --- .../roles/test_command_shell/tasks/main.yml | 18 +++++++++++++----- .../integration/roles/test_copy/tasks/main.yml | 6 +++++- .../roles/test_good_parsing/tasks/main.yml | 2 +- test/utils/shippable/remote-integration.sh | 15 --------------- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/test/integration/roles/test_command_shell/tasks/main.yml b/test/integration/roles/test_command_shell/tasks/main.yml index 976843e369b..226f8df622f 100644 --- a/test/integration/roles/test_command_shell/tasks/main.yml +++ b/test/integration/roles/test_command_shell/tasks/main.yml @@ -33,6 +33,14 @@ - name: prep our test script copy: src=remove_afile.sh dest="{{ output_dir_test }}" mode=0755 +- name: locate bash + shell: which bash + register: bash + +- name: locate sha1sum/shasum + shell: which sha1sum || which shasum + register: sha1sum + ## ## command ## @@ -53,7 +61,7 @@ # 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" +# command: "{{output_dir_test | expanduser}}/test.sh executable={{ bash.stdout }}" # register: command_result1 # #- name: assert that the script executed correctly with command @@ -133,7 +141,7 @@ # FIXME doesn't pass the expected stdout #- name: execute the test.sh script -# shell: "{{output_dir_test | expanduser}}/test.sh executable=/bin/bash" +# shell: "{{output_dir_test | expanduser}}/test.sh executable={{ bash.stdout }}" # register: shell_result1 # #- name: assert that the shell executed correctly @@ -174,13 +182,13 @@ - name: execute a shell command using a literal multiline block args: - executable: /bin/bash + executable: "{{ bash.stdout }}" shell: | echo this is a \ "multiline echo" \ "with a new line in quotes" \ - | sha1sum \ + | {{ sha1sum.stdout }} \ | tr -s ' ' \ | cut -f1 -d ' ' echo "this is a second line" @@ -196,7 +204,7 @@ - name: execute a shell command using a literal multiline block with arguments in it shell: | - executable=/bin/bash + executable="{{ bash.stdout }}" creates={{output_dir_test | expanduser}}/afile.txt echo "test" register: shell_result6 diff --git a/test/integration/roles/test_copy/tasks/main.yml b/test/integration/roles/test_copy/tasks/main.yml index 8153ba1508a..19559090654 100644 --- a/test/integration/roles/test_copy/tasks/main.yml +++ b/test/integration/roles/test_copy/tasks/main.yml @@ -19,6 +19,10 @@ - name: record the output directory set_fact: output_file={{output_dir}}/foo.txt +- name: locate sha1sum/shasum + shell: which sha1sum || which shasum + register: sha1sum + - name: initiate a basic copy, and also test the mode copy: src=foo.txt dest={{output_file}} mode=0444 register: copy_result @@ -247,7 +251,7 @@ - stat_link_result.stat.islnk - name: get the checksum of the link target - shell: sha1sum {{output_dir}}/follow_test | cut -f1 -sd ' ' + shell: "{{ sha1sum.stdout }} {{output_dir}}/follow_test | cut -f1 -sd ' '" register: target_file_result - name: assert that the link target was updated diff --git a/test/integration/roles/test_good_parsing/tasks/main.yml b/test/integration/roles/test_good_parsing/tasks/main.yml index 46ec2db4a9e..418b6d4040b 100644 --- a/test/integration/roles/test_good_parsing/tasks/main.yml +++ b/test/integration/roles/test_good_parsing/tasks/main.yml @@ -98,7 +98,7 @@ result.cmd == "echo foo=bar foo=bar" - name: raw duplicates, noop - raw: /bin/true foo=bar foo=bar + raw: env true foo=bar foo=bar - name: multi-line inline shell commands (should use script module but hey) are a thing shell: "{{ multi_line }}" diff --git a/test/utils/shippable/remote-integration.sh b/test/utils/shippable/remote-integration.sh index 639f2be3104..ab76bdd09a7 100644 --- a/test/utils/shippable/remote-integration.sh +++ b/test/utils/shippable/remote-integration.sh @@ -47,21 +47,6 @@ pip install \ virtualenv \ jmespath -# FIXME: tests assume bash is in /bin/bash -if [ ! -f /bin/bash ]; then - ln -s /usr/local/bin/bash /bin/bash -fi - -# FIXME: tests assume true is in /bin/true -if [ ! -f /bin/true ]; then - ln -s /usr/bin/true /bin/true -fi - -# FIXME: tests assume sha1sum is available (some platforms have shasum instead) -if [ ! -f /usr/local/bin/sha1sum ]; then - ln -s /usr/local/bin/shasum /usr/local/bin/sha1sum -fi - # Tests assume loopback addresses other than 127.0.0.1 will work. # Add aliases for loopback addresses used by tests.