56 lines
2.0 KiB
YAML
56 lines
2.0 KiB
YAML
---
|
|
# Run: ansible-playbook tests/inputs/test_inputs.yml
|
|
- name: Strict input validator fixture tests
|
|
hosts: localhost
|
|
gather_facts: false
|
|
connection: local
|
|
vars_files:
|
|
- inputs_fixtures.yml
|
|
tasks:
|
|
- name: Run each input fixture
|
|
ansible.builtin.include_tasks: _assert_inputs.yml
|
|
loop: "{{ inputs_fixtures }}"
|
|
loop_control:
|
|
loop_var: inf
|
|
label: "{{ inf.name }}"
|
|
|
|
- name: Refuse a variable declared by two specs
|
|
block:
|
|
- name: Run the validator with the fixture spec twice
|
|
validate_inputs:
|
|
specs:
|
|
- "{{ playbook_dir }}/fixture_spec.yml"
|
|
- "{{ playbook_dir }}/fixture_spec.yml"
|
|
register: inputs_duplicate_result
|
|
rescue:
|
|
- name: Keep the duplicate-declaration failure
|
|
ansible.builtin.set_fact:
|
|
inputs_duplicate_result: "{{ ansible_failed_result }}"
|
|
|
|
- name: Assert the duplicate declaration was refused
|
|
ansible.builtin.assert:
|
|
that:
|
|
- inputs_duplicate_result.msg is search('fixture is declared by both')
|
|
fail_msg: "[inputs duplicate] got {{ inputs_duplicate_result.msg | default('') }}"
|
|
success_msg: "[inputs duplicate] OK"
|
|
|
|
- name: Validate a host var holding values that cannot be decrypted
|
|
block:
|
|
- name: Run the validator on the vaulted host var
|
|
validate_inputs:
|
|
specs:
|
|
- "{{ playbook_dir }}/fixture_spec.yml"
|
|
register: inputs_vault_result
|
|
rescue:
|
|
- name: Keep the failed vault result
|
|
ansible.builtin.set_fact:
|
|
inputs_vault_result: "{{ ansible_failed_result }}"
|
|
|
|
- name: Assert a vaulted string passes and a vaulted non-list is reported
|
|
ansible.builtin.assert:
|
|
that:
|
|
- >-
|
|
inputs_vault_result.errors | default([]) == ['fixture.servers: expected list, got str']
|
|
fail_msg: "[inputs vault] got {{ inputs_vault_result.errors | default([]) }}"
|
|
success_msg: "[inputs vault] OK"
|