mirror of
https://github.com/ansible-collections/community.docker.git
synced 2025-12-16 20:08:41 +00:00
docker_config integration tests for template_driver (#347)
* template_driver integration tests * adding comment * naming swarm default * Apply suggestions from code review * Only run tests for new enough Docker SDK for Python and Docker API version. Co-authored-by: Sasha Jenner <sasha.jenner@cba.com.au> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
e5ba309f03
commit
560bf1d3a3
@ -11,6 +11,7 @@
|
||||
|
||||
- name: Create a Swarm cluster
|
||||
docker_swarm:
|
||||
name: default
|
||||
state: present
|
||||
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||
|
||||
@ -226,6 +227,99 @@
|
||||
that:
|
||||
- output.failed
|
||||
|
||||
# template_driver tests
|
||||
|
||||
- when: docker_py_version is version('5.0.3', '>=') and docker_api_version is version('1.37', '>=')
|
||||
block:
|
||||
|
||||
- name: Create regular config
|
||||
docker_config:
|
||||
name: db_password
|
||||
data: opensesame!
|
||||
state: present
|
||||
|
||||
- name: Update config with template_driver
|
||||
docker_config:
|
||||
name: db_password
|
||||
data: opensesame!
|
||||
template_driver: golang
|
||||
state: present
|
||||
register: output
|
||||
|
||||
- name: Assert config was updated
|
||||
assert:
|
||||
that:
|
||||
- output is changed
|
||||
|
||||
- name: Invalid template_driver
|
||||
docker_config:
|
||||
name: db_password
|
||||
data: opensesame!
|
||||
template_driver: "not a template driver"
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
register: output
|
||||
|
||||
- name: Assert failure when called with invalid template_driver
|
||||
assert:
|
||||
that:
|
||||
- 'output.failed'
|
||||
- 'output.msg == "value of template_driver must be one of: golang, got: not a template driver"'
|
||||
|
||||
- name: Create config again
|
||||
docker_config:
|
||||
name: db_password
|
||||
data: opensesame!
|
||||
template_driver: golang
|
||||
state: present
|
||||
register: output
|
||||
|
||||
- name: Assert create config is idempotent
|
||||
assert:
|
||||
that:
|
||||
- output is not changed
|
||||
|
||||
# data is the docker swarm's name
|
||||
- name: Update config with template data
|
||||
docker_config:
|
||||
name: db_password
|
||||
data: "{{ '{{' }} .Service.Name {{ '}}' }}"
|
||||
template_driver: golang
|
||||
state: present
|
||||
register: output
|
||||
|
||||
- name: Inspect config
|
||||
command: "docker config inspect {{ output.config_id }}"
|
||||
register: inspect
|
||||
|
||||
- name: Show inspection result
|
||||
debug:
|
||||
var: inspect
|
||||
|
||||
- name: assert config creation succeeded
|
||||
assert:
|
||||
that:
|
||||
- "'db_password' in inspect.stdout"
|
||||
- "'ansible_key' in inspect.stdout"
|
||||
- "'\"Data\": \"default\"' in inspect.stdout"
|
||||
- "'Templating' in inspect.stdout"
|
||||
- "'\"Name\": \"golang\"' in inspect.stdout"
|
||||
|
||||
- name: Remove config
|
||||
docker_config:
|
||||
name: db_password
|
||||
state: absent
|
||||
|
||||
- name: Check that config is removed
|
||||
command: "docker config inspect {{ output.config_id }}"
|
||||
register: output
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Assert config was removed
|
||||
assert:
|
||||
that:
|
||||
- output.failed
|
||||
|
||||
always:
|
||||
- name: Remove a Swarm cluster
|
||||
docker_swarm:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user