Skip to content

Commit

Permalink
Add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Oct 19, 2024
1 parent be5564d commit e116257
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

- vars:
pname: "{{ name_prefix }}-exit"
cname: "{{ name_prefix }}-container"
project_src: "{{ remote_tmp_dir }}/{{ pname }}"
test_service: |
services:
{{ cname }}:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "exit 0"'
stop_grace_period: 1s
block:
- name: Registering container name
set_fact:
cnames: "{{ cnames + [pname ~ '-' ~ cname ~ '-1'] }}"
dnetworks: "{{ dnetworks + [pname ~ '_default'] }}"

- name: Create project directory
file:
path: '{{ project_src }}'
state: directory

- name: Template default project file
copy:
dest: '{{ project_src }}/docker-compose.yml'
content: '{{ test_service }}'

- name: Present (check)
docker_compose_v2:
project_src: '{{ project_src }}'
state: present
wait: true
check_mode: true
register: present_1_check

- name: Present
docker_compose_v2:
project_src: '{{ project_src }}'
state: present
wait: true
register: present_1
ignore_errors: true

- name: Cleanup
docker_compose_v2:
project_src: '{{ project_src }}'
state: absent

- assert:
that:
- present_1_check is changed
- present_1_check.warnings | default([]) | select('regex', ' Please report this at ') | length == 0
- present_1 is failed
- present_1.containers | length == 1
- present_1.containers[0].Name == pname ~ '-' ~ cname ~ '-1'
- present_1.containers[0].Image == docker_test_image_alpine
- present_1.containers[0].State == 'exited'
- present_1.containers[0].ExitCode == 0
- present_1.images | length == 1
- present_1.images[0].ContainerName == pname ~ '-' ~ cname ~ '-1'
- present_1.images[0].Repository == (docker_test_image_alpine | split(':') | first)
- present_1.images[0].Tag == (docker_test_image_alpine | split(':') | last)
- present_1.warnings | default([]) | select('regex', ' Please report this at ') | length == 0
- >-
("container " ~ pname ~ '-' ~ cname ~ "-1 exited (0)") in present_1.msg
66 changes: 66 additions & 0 deletions tests/unit/plugins/module_utils/test_compose_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,72 @@
],
[],
),
(
# https://github.com/ansible-collections/community.docker/issues/978
'2.28.1-unknown', # TODO: find out actual version!
'2.28.1', # TODO: find out actual version!
False,
True,
" Network create_users_db_default Creating\n"
" Network create_users_db_default Created\n"
" Container create_users_db-init Creating\n"
" Container create_users_db-init Created\n"
" Container create_users_db-init Starting\n"
" Container create_users_db-init Started\n"
" Container create_users_db-init Waiting\n"
"container create_users_db-init exited (0)\n",
[
Event(
'network',
'create_users_db_default',
'Creating',
None,
),
Event(
'network',
'create_users_db_default',
'Created',
None,
),
Event(
'container',
'create_users_db-init',
'Creating',
None,
),
Event(
'container',
'create_users_db-init',
'Created',
None,
),
Event(
'container',
'create_users_db-init',
'Starting',
None,
),
Event(
'container',
'create_users_db-init',
'Started',
None,
),
Event(
'container',
'create_users_db-init',
'Waiting',
None,
),
Event(
'unknown',
'',
'Error',
'container create_users_db-init exited (0)',
),
],
[],
),
]

_ALL_TEST_CASES = EVENT_TEST_CASES + EXTRA_TEST_CASES
Expand Down

0 comments on commit e116257

Please sign in to comment.