[coverage] improve test coverage for vars lookup (#74546)
This commit is contained in:
parent
30912b6a47
commit
244bf9c640
1 changed files with 40 additions and 0 deletions
|
@ -14,3 +14,43 @@
|
||||||
that:
|
that:
|
||||||
- 'var_host_info[0] == ansible_host'
|
- 'var_host_info[0] == ansible_host'
|
||||||
- 'var_host_info[1] == ansible_connection'
|
- 'var_host_info[1] == ansible_connection'
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: EXPECTED FAILURE - test invalid var
|
||||||
|
debug:
|
||||||
|
var: '{{ lookup("vars", "doesnotexist") }}'
|
||||||
|
|
||||||
|
- fail:
|
||||||
|
msg: "should not get here"
|
||||||
|
|
||||||
|
rescue:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- ansible_failed_task.name == "EXPECTED FAILURE - test invalid var"
|
||||||
|
- expected in ansible_failed_result.msg
|
||||||
|
vars:
|
||||||
|
expected: "No variable found with this name: doesnotexist"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: EXPECTED FAILURE - test invalid var type
|
||||||
|
debug:
|
||||||
|
var: '{{ lookup("vars", 42) }}'
|
||||||
|
|
||||||
|
- fail:
|
||||||
|
msg: "should not get here"
|
||||||
|
|
||||||
|
rescue:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- ansible_failed_task.name == "EXPECTED FAILURE - test invalid var type"
|
||||||
|
- expected in ansible_failed_result.msg
|
||||||
|
vars:
|
||||||
|
expected: "Invalid setting identifier, \"42\" is not a string"
|
||||||
|
|
||||||
|
- name: test default
|
||||||
|
set_fact:
|
||||||
|
expected_default_var: '{{ lookup("vars", "doesnotexist", default="some text") }}'
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- expected_default_var == "some text"
|
||||||
|
|
Loading…
Reference in a new issue