Skip to content

Commit dd1fa67

Browse files
committed
Add tests for podman_container_exec
Signed-off-by: nishipy <[email protected]>
1 parent 5c8b6fb commit dd1fa67

File tree

1 file changed

+68
-0
lines changed
  • tests/integration/targets/podman_container_exec/tasks

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
- name: Test podman_container_exec
2+
block:
3+
- name: Generate random value for container name
4+
set_fact:
5+
container_name: "{{ 'ansible-test-podman-%0x' % ((2**32) | random) }}"
6+
7+
- name: Make sure container doesn't exist
8+
containers.podman.podman_container:
9+
executable: "{{ test_executable | default('podman') }}"
10+
name: "{{ container_name }}"
11+
state: absent
12+
13+
- name: Test exec when the container doesn't exist
14+
containers.podman.podman_container_exec:
15+
name: "{{ container_name }}"
16+
command: "cat /etc/redhat-release"
17+
ignore_errors: true
18+
register: no_container
19+
20+
- name: Create and start a postgres container for testing
21+
containers.podman.podman_container:
22+
name: "{{ container_name }}"
23+
image: registry.access.redhat.com/ubi8
24+
command: sleep 1d
25+
state: started
26+
27+
- name: Test exec with command and workdir options
28+
containers.podman.podman_container_exec:
29+
name: "{{ container_name }}"
30+
command: "cat redhat-release"
31+
workdir: /etc
32+
register: exec1
33+
34+
- name: Test exec when argv and env options
35+
containers.podman.podman_container_exec:
36+
name: "{{ container_name }}"
37+
argv:
38+
- /bin/sh
39+
- -c
40+
- echo $HELLO $BYE
41+
env:
42+
HELLO: hello world
43+
BYE: goodbye world
44+
register: exec2
45+
46+
- name: Test exec with detach option
47+
containers.podman.podman_container_exec:
48+
name: "{{ container_name }}"
49+
command: "cat redhat-release"
50+
detach: true
51+
register: exec3
52+
53+
- name: Check if the result is as expected
54+
assert:
55+
that:
56+
- no_container is failed
57+
- "'Red Hat Enterprise Linux' in exec1.stdout"
58+
- "'hello world' in exec2.stdout"
59+
- "'goodbye world' in exec2.stdout"
60+
- exec3.exec_id is defined
61+
-
62+
63+
always:
64+
- name: Cleanup
65+
containers.podman.podman_container:
66+
executable: "{{ test_executable | default('podman') }}"
67+
name: "{{ container_name }}"
68+
state: absent

0 commit comments

Comments
 (0)