Skip to content

Commit 98e85fb

Browse files
committed
Switch to more efficient and compact test setup.
1 parent 6812f62 commit 98e85fb

File tree

3 files changed

+22
-35
lines changed

3 files changed

+22
-35
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.retry
2+
tests/test.sh

.travis.yml

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,27 @@ services: docker
33

44
env:
55
- distro: centos7
6-
init: /usr/lib/systemd/systemd
7-
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
86
- distro: centos6
9-
init: /sbin/init
10-
run_opts: ""
117
- distro: fedora24
12-
init: /usr/lib/systemd/systemd
13-
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
148
- distro: ubuntu1604
15-
init: /lib/systemd/systemd
16-
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
179
- distro: ubuntu1404
18-
init: /sbin/init
19-
run_opts: ""
2010
- distro: ubuntu1204
21-
init: /sbin/init
22-
run_opts: ""
2311
- distro: debian8
24-
init: /lib/systemd/systemd
25-
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
26-
27-
before_install:
28-
# Pull container.
29-
- 'docker pull geerlingguy/docker-${distro}-ansible:latest'
3012

3113
script:
32-
- container_id=$(mktemp)
33-
# Run container in detached state.
34-
- 'docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"'
35-
36-
# Ansible syntax check.
37-
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check'
14+
# Configure test script so we can run extra tests after playbook is run.
15+
- export container_id=$(date +%s)
16+
- export cleanup=false
3817

39-
# Test role.
40-
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml'
18+
# Download test shim.
19+
- wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
20+
- chmod +x ${PWD}/tests/test.sh
4121

42-
# Test role idempotence.
43-
- idempotence=$(mktemp)
44-
- docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml | tee -a ${idempotence}
45-
- >
46-
tail ${idempotence}
47-
| grep -q 'changed=0.*failed=0'
48-
&& (echo 'Idempotence test: pass' && exit 0)
49-
|| (echo 'Idempotence test: fail' && exit 1)
22+
# Run tests.
23+
- ${PWD}/tests/test.sh
5024

5125
# Ensure Java is installed.
52-
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm which java'
26+
- 'docker exec --tty ${container_id} env TERM=xterm which java'
5327

5428
notifications:
5529
webhooks: https://galaxy.ansible.com/api/v1/notifications/

tests/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Ansible Role tests
2+
3+
To run the test playbook(s) in this directory:
4+
5+
1. Install and start Docker.
6+
1. Download the test shim (see .travis.yml file for the URL) into `tests/test.sh`:
7+
- `wget -O tests/test.sh wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/`
8+
1. Make the test shim executable: `chmod +x tests/test.sh`.
9+
1. Run (from the role root directory) `distro=[distro] playbook=[playbook] ./tests/test.sh`
10+
11+
If you don't want the container to be automatically deleted after the test playbook is run, add the following environment variables: `cleanup=false container_id=$(date +%s)`

0 commit comments

Comments
 (0)