diff options
author | James Tanner <tanner.jc@gmail.com> | 2013-11-13 15:52:09 -0500 |
---|---|---|
committer | James Tanner <tanner.jc@gmail.com> | 2013-11-13 15:52:40 -0500 |
commit | 33242cacf3c4b12381bf0f79f58c8d3227bd340d (patch) | |
tree | 43ab1e17db06b34845535f0f282915a4e8bd5cd5 /test | |
parent | 9a7765daf7d7039afe83f908c2641e44205a2f62 (diff) | |
parent | 3ad61ef3101de5183790fd32c06688fac51e9a80 (diff) | |
download | ansible-33242cacf3c4b12381bf0f79f58c8d3227bd340d.tar.gz |
Merge pull request #4375 from pfalcon/ansible
copy: Implement recursive copying if src is a directory.
Diffstat (limited to 'test')
-rw-r--r-- | test/TestPlayBook.py | 17 | ||||
-rw-r--r-- | test/playbook-recursive-copy.yml | 133 | ||||
-rw-r--r-- | test/test_recursive_copy/files/subdir/subdir2/subdir3/test1 | 2 | ||||
-rw-r--r-- | test/test_recursive_copy/files/subdir/subdir2/subdir3/test2 | 2 |
4 files changed, 154 insertions, 0 deletions
diff --git a/test/TestPlayBook.py b/test/TestPlayBook.py index 8a4ceb9584..fcee39db4f 100644 --- a/test/TestPlayBook.py +++ b/test/TestPlayBook.py @@ -393,6 +393,23 @@ class TestPlaybook(unittest.TestCase): assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True) + def test_recursive_copy(self): + pb = 'test/playbook-recursive-copy.yml' + actual = self._run(pb) + + expected = { + "localhost": { + "changed": 65, + "failures": 0, + "ok": 73, + "skipped": 0, + "unreachable": 0 + } + } + + assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True) + + def _compare_file_output(self, filename, expected_lines): actual_lines = [] with open(filename) as f: diff --git a/test/playbook-recursive-copy.yml b/test/playbook-recursive-copy.yml new file mode 100644 index 0000000000..a4c6b948d8 --- /dev/null +++ b/test/playbook-recursive-copy.yml @@ -0,0 +1,133 @@ +--- +# To run me manually, use: -i "localhost," +- hosts: localhost + connection: local + gather_facts: no + vars: + - testdir: /tmp/ansible-rcopy + - filesdir: test_recursive_copy/files + tasks: + + # + # First, regression tests for single-file behavior + # + + - name: "src single file, dest file" + command: rm -rf {{testdir}} + - file: state=directory dest={{testdir}} + - copy: src={{filesdir}}/subdir/subdir2/subdir3/test1 dest={{testdir}}/file1 + register: res + - command: test -f {{testdir}}/file1 + - command: test "{{res.changed}}" == "True" + - copy: src={{filesdir}}/subdir/subdir2/subdir3/test1 dest={{testdir}}/file1 + register: res + - command: test "{{res.changed}}" == "False" + + - name: "src single file, dest dir w/trailing slash" + command: rm -rf {{testdir}} + - file: state=directory dest={{testdir}} + - copy: src={{filesdir}}/subdir/subdir2/subdir3/test1 dest={{testdir}}/ + register: res + - command: test -f {{testdir}}/test1 + - command: test "{{res.changed}}" == "True" + - copy: src={{filesdir}}/subdir/subdir2/subdir3/test1 dest={{testdir}}/ + register: res + - command: test "{{res.changed}}" == "False" + + - name: "src single file, dest dir wo/trailing slash - doesn't behave in sane way" + command: rm -rf {{testdir}} + - file: state=directory dest={{testdir}} + - copy: src={{filesdir}}/subdir/subdir2/subdir3/test1 dest={{testdir}} + register: res + - shell: test -f {{testdir}}/test1 + - command: test "{{res.changed}}" == "True" + - copy: src={{filesdir}}/subdir/subdir2/subdir3/test1 dest={{testdir}} + register: res + - command: test "{{res.changed}}" == "False" + + # + # Now, test recursive behavior + # + + - name: "src dir w/trailing slash, dest w/trailing slash" + command: rm -rf {{testdir}} + - file: state=directory dest={{testdir}} + - copy: src={{filesdir}}/subdir/ dest={{testdir}}/ + register: res + - command: test -d {{testdir}}/subdir2 + - command: test -d {{testdir}}/subdir2/subdir3 + - command: test -d {{testdir}}/subdir2/subdir3 + - command: test -f {{testdir}}/subdir2/subdir3/test1 + - command: test -f {{testdir}}/subdir2/subdir3/test2 + - command: test "{{res.changed}}" == "True" + - copy: src={{filesdir}}/subdir/ dest={{testdir}}/ + register: res + - command: test "{{res.changed}}" == "False" + + # Expecting the same behavior + - name: "src dir w/trailing slash, dest wo/trailing slash" + command: rm -rf {{testdir}} + - file: state=directory dest={{testdir}} + - copy: src={{filesdir}}/subdir/ dest={{testdir}} + register: res + - command: test -d {{testdir}}/subdir2 + - command: test -d {{testdir}}/subdir2/subdir3 + - command: test -d {{testdir}}/subdir2/subdir3 + - command: test -f {{testdir}}/subdir2/subdir3/test1 + - command: test -f {{testdir}}/subdir2/subdir3/test2 + - command: test "{{res.changed}}" == "True" + - copy: src={{filesdir}}/subdir/ dest={{testdir}} + register: res + - command: test "{{res.changed}}" == "False" + + - name: "src dir wo/trailing slash, dest w/trailing slash" + command: rm -rf {{testdir}} + - file: state=directory dest={{testdir}} + - copy: src={{filesdir}}/subdir dest={{testdir}}/ + register: res + - command: test -d {{testdir}}/subdir/subdir2 + - command: test -d {{testdir}}/subdir/subdir2/subdir3 + - command: test -d {{testdir}}/subdir/subdir2/subdir3 + - command: test -f {{testdir}}/subdir/subdir2/subdir3/test1 + - command: test -f {{testdir}}/subdir/subdir2/subdir3/test2 + - command: test "{{res.changed}}" == "True" + - copy: src={{filesdir}}/subdir dest={{testdir}}/ + register: res + - command: test "{{res.changed}}" == "False" + + # Expecting the same behavior + - name: "src dir wo/trailing slash, dest wo/trailing slash" + command: rm -rf {{testdir}} + - file: state=directory dest={{testdir}} + - copy: src={{filesdir}}/subdir dest={{testdir}} + register: res + - command: test -d {{testdir}}/subdir/subdir2 + - command: test -d {{testdir}}/subdir/subdir2/subdir3 + - command: test -d {{testdir}}/subdir/subdir2/subdir3 + - command: test -f {{testdir}}/subdir/subdir2/subdir3/test1 + - command: test -f {{testdir}}/subdir/subdir2/subdir3/test2 + - command: test "{{res.changed}}" == "True" + - copy: src={{filesdir}}/subdir dest={{testdir}} + register: res + - command: test "{{res.changed}}" == "False" + + + - name: "Verifying notify handling for recursive files" + command: rm -rf {{testdir}} + - file: state=directory dest={{testdir}} + - copy: src={{filesdir}}/subdir dest={{testdir}} + notify: + - files changed + - meta: flush_handlers + - command: test -f {{testdir}}/notify_fired + + - command: rm {{testdir}}/notify_fired + - copy: src={{filesdir}}/subdir dest={{testdir}} + notify: + - files changed + - meta: flush_handlers + - command: test ! -f {{testdir}}/notify_fired + + handlers: + - name: files changed + command: touch {{testdir}}/notify_fired diff --git a/test/test_recursive_copy/files/subdir/subdir2/subdir3/test1 b/test/test_recursive_copy/files/subdir/subdir2/subdir3/test1 new file mode 100644 index 0000000000..9f71d140ff --- /dev/null +++ b/test/test_recursive_copy/files/subdir/subdir2/subdir3/test1 @@ -0,0 +1,2 @@ +test1 + diff --git a/test/test_recursive_copy/files/subdir/subdir2/subdir3/test2 b/test/test_recursive_copy/files/subdir/subdir2/subdir3/test2 new file mode 100644 index 0000000000..4a19b05426 --- /dev/null +++ b/test/test_recursive_copy/files/subdir/subdir2/subdir3/test2 @@ -0,0 +1,2 @@ +test2 + |