From 0df166e7c0f629026ebed6d4fc70ed74b6be93f7 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 19 Feb 2014 14:36:54 -0500 Subject: [PATCH] Copy tests WIP, fix bug in assert module upgrades where the wrong value was being checked. --- lib/ansible/runner/action_plugins/assert.py | 2 +- .../roles/test_copy/files/subdir/bar.txt | 1 + .../test_copy/files/subdir/subdir2/baz.txt | 1 + .../roles/test_copy/tasks/main.yml | 46 ++++++++++++++++++- tests_new/integration/test.sh | 2 +- 5 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 tests_new/integration/roles/test_copy/files/subdir/bar.txt create mode 100644 tests_new/integration/roles/test_copy/files/subdir/subdir2/baz.txt diff --git a/lib/ansible/runner/action_plugins/assert.py b/lib/ansible/runner/action_plugins/assert.py index 210dbc0af1..fbd0b3888a 100644 --- a/lib/ansible/runner/action_plugins/assert.py +++ b/lib/ansible/runner/action_plugins/assert.py @@ -50,7 +50,7 @@ class ActionModule(object): args['that'] = [ args['that'] ] for that in args['that']: - result = utils.check_conditional(args['that'], self.runner.basedir, inject, fail_on_undefined=True) + result = utils.check_conditional(that, self.runner.basedir, inject, fail_on_undefined=True) if not result: return ReturnData(conn=conn, result=dict(failed=True, assertion=that, evaluated_to=result)) diff --git a/tests_new/integration/roles/test_copy/files/subdir/bar.txt b/tests_new/integration/roles/test_copy/files/subdir/bar.txt new file mode 100644 index 0000000000..76018072e0 --- /dev/null +++ b/tests_new/integration/roles/test_copy/files/subdir/bar.txt @@ -0,0 +1 @@ +baz diff --git a/tests_new/integration/roles/test_copy/files/subdir/subdir2/baz.txt b/tests_new/integration/roles/test_copy/files/subdir/subdir2/baz.txt new file mode 100644 index 0000000000..76018072e0 --- /dev/null +++ b/tests_new/integration/roles/test_copy/files/subdir/subdir2/baz.txt @@ -0,0 +1 @@ +baz diff --git a/tests_new/integration/roles/test_copy/tasks/main.yml b/tests_new/integration/roles/test_copy/tasks/main.yml index 5aa40f036d..81f04ca9e4 100644 --- a/tests_new/integration/roles/test_copy/tasks/main.yml +++ b/tests_new/integration/roles/test_copy/tasks/main.yml @@ -91,9 +91,51 @@ that: - "not copy_result4|changed" -# TODO: test recursive copy -# TODO: test copy where destination is a directory like {{output_dir}}/ +# test recursive copy + +- name: set the output subdirectory + set_fact: output_subdir={{output_dir}}/sub + +- name: make an output subdirectory + file: name={{output_subdir}} state=directory + +- name: test recursive copy to directory + copy: src=subdir dest={{output_subdir}} + register: recursive_copy_result + +- debug: var=recursive_copy_result + +- name: check that a file in a directory was transferred + stat: path={{output_dir}}/sub/subdir/bar.txt + register: stat_bar + +- name: check that a file in a deeper directory was transferred + stat: path={{output_dir}}/sub/subdir/subdir2/bar2.txt + register: stat_bar2 + + +- debug: var=stat_bar + +- fail: msg="boom!" + when: not stat_bar.stat.exists + +- assert: { that: "stat_bar.stat.exists" } + +- name: assert recursive copy things + assert: + that: + - "stat_bar.stat.exists" + - "stat_bar2.stat.exists" + # TODO: test that copy fails if the path does not exist + +- name: assert invalid copy location fails + copy: src=invalid_file_location_does_not_exist dest={{output_dir}}/file.txt + ignore_errors: True + register: failed_copy + +- debug: var=failed_copy + # TODO: ... diff --git a/tests_new/integration/test.sh b/tests_new/integration/test.sh index dae0cdeae2..74e23a258b 100644 --- a/tests_new/integration/test.sh +++ b/tests_new/integration/test.sh @@ -1 +1 @@ -ansible-playbook non_destructive.yml -i inventory -e output_dir=~/ansible_testing -v +ansible-playbook non_destructive.yml -i inventory -e output_dir=~/ansible_testing -v $*