diff options
author | Toshio Kuratomi <a.badger@gmail.com> | 2018-01-30 14:46:14 -0800 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2018-01-31 13:55:49 -0800 |
commit | e8cfe05e3753bcab67808328c641289314134ff1 (patch) | |
tree | 77d4b3cddaff23fc3f46b7e9a6366a72a365d25f | |
parent | 715b930fc8ded83e0f7f881303a8d43b220ca67a (diff) | |
download | ansible-e8cfe05e3753bcab67808328c641289314134ff1.tar.gz |
Test behaviour of loop keyword plus lookup plugins
We introduced the new loop keyword as a replacement for with without
adding tests that it behaved as we expected. This test asserts that
behaviour.
Incidentally, it also shows how to use parameters with lookups and loops
now.
-rw-r--r-- | test/integration/targets/loops/files/data1.txt | 1 | ||||
-rw-r--r-- | test/integration/targets/loops/files/data2.txt | 1 | ||||
-rw-r--r-- | test/integration/targets/loops/tasks/main.yml | 128 | ||||
-rw-r--r-- | test/integration/targets/loops/vars/main.yml | 7 |
4 files changed, 137 insertions, 0 deletions
diff --git a/test/integration/targets/loops/files/data1.txt b/test/integration/targets/loops/files/data1.txt new file mode 100644 index 0000000000..b044a82a86 --- /dev/null +++ b/test/integration/targets/loops/files/data1.txt @@ -0,0 +1 @@ + Hello World diff --git a/test/integration/targets/loops/files/data2.txt b/test/integration/targets/loops/files/data2.txt new file mode 100644 index 0000000000..e9359ad180 --- /dev/null +++ b/test/integration/targets/loops/files/data2.txt @@ -0,0 +1 @@ + Olá Mundo diff --git a/test/integration/targets/loops/tasks/main.yml b/test/integration/targets/loops/tasks/main.yml index 7fa6d0d03a..5d61df6de0 100644 --- a/test/integration/targets/loops/tasks/main.yml +++ b/test/integration/targets/loops/tasks/main.yml @@ -18,3 +18,131 @@ - assert: that: - '(after.stdout |int) - (before.stdout|int) >= 4' + +# +# Tests of loop syntax with args +# + +- name: Test that with_list works with a list + ping: + data: '{{ item }}' + with_list: + - 'Hello World' + - 'Olá Mundo' + register: results + +- name: Assert that we ran the module twice with the correct strings + assert: + that: + - 'results["results"][0]["ping"] == "Hello World"' + - 'results["results"][1]["ping"] == "Olá Mundo"' + +- name: Test that with_list works with a list inside a variable + ping: + data: '{{ item }}' + with_list: '{{ phrases }}' + register: results2 + +- name: Assert that we ran the module twice with the correct strings + assert: + that: + - 'results2["results"][0]["ping"] == "Hello World"' + - 'results2["results"][1]["ping"] == "Olá Mundo"' + +- name: Test that loop works with a manual list + ping: + data: '{{ item }}' + loop: + - 'Hello World' + - 'Olá Mundo' + register: results3 + +- name: Assert that we ran the module twice with the correct strings + assert: + that: + - 'results3["results"][0]["ping"] == "Hello World"' + - 'results3["results"][1]["ping"] == "Olá Mundo"' + +- name: Test that loop works with a list in a variable + ping: + data: '{{ item }}' + loop: '{{ phrases }}' + register: results4 + +- name: Assert that we ran the module twice with the correct strings + assert: + that: + - 'results4["results"][0]["ping"] == "Hello World"' + - 'results4["results"][1]["ping"] == "Olá Mundo"' + +- name: Test that loop works with a list via the list lookup + ping: + data: '{{ item }}' + loop: '{{ lookup("list", "Hello World", "Olá Mundo", wantlist=True) }}' + register: results5 + +- name: Assert that we ran the module twice with the correct strings + assert: + that: + - 'results5["results"][0]["ping"] == "Hello World"' + - 'results5["results"][1]["ping"] == "Olá Mundo"' + +- name: Test that loop works with a list in a variable via the list lookup + ping: + data: '{{ item }}' + loop: '{{ lookup("list", wantlist=True, *phrases) }}' + register: results6 + +- name: Assert that we ran the module twice with the correct strings + assert: + that: + - 'results6["results"][0]["ping"] == "Hello World"' + - 'results6["results"][1]["ping"] == "Olá Mundo"' + +- name: Test that loop works with a list via the query lookup + ping: + data: '{{ item }}' + loop: '{{ query("list", "Hello World", "Olá Mundo") }}' + register: results7 + +- name: Assert that we ran the module twice with the correct strings + assert: + that: + - 'results7["results"][0]["ping"] == "Hello World"' + - 'results7["results"][1]["ping"] == "Olá Mundo"' + +- name: Test that loop works with a list in a variable via the query lookup + ping: + data: '{{ item }}' + loop: '{{ q("list", *phrases) }}' + register: results8 + +- name: Assert that we ran the module twice with the correct strings + assert: + that: + - 'results8["results"][0]["ping"] == "Hello World"' + - 'results8["results"][1]["ping"] == "Olá Mundo"' + +- name: Test that loop works with a list and keyword args + ping: + data: '{{ item }}' + loop: '{{ q("file", "data1.txt", "data2.txt", lstrip=True) }}' + register: results9 + +- name: Assert that we ran the module twice with the correct strings + assert: + that: + - 'results9["results"][0]["ping"] == "Hello World"' + - 'results9["results"][1]["ping"] == "Olá Mundo"' + +- name: Test that loop works with a list in variable and keyword args + ping: + data: '{{ item }}' + loop: '{{ q("file", lstrip=True, *filenames) }}' + register: results10 + +- name: Assert that we ran the module twice with the correct strings + assert: + that: + - 'results10["results"][0]["ping"] == "Hello World"' + - 'results10["results"][1]["ping"] == "Olá Mundo"' diff --git a/test/integration/targets/loops/vars/main.yml b/test/integration/targets/loops/vars/main.yml new file mode 100644 index 0000000000..2d85bf824b --- /dev/null +++ b/test/integration/targets/loops/vars/main.yml @@ -0,0 +1,7 @@ +--- +phrases: + - 'Hello World' + - 'Olá Mundo' +filenames: + - 'data1.txt' + - 'data2.txt' |