Skip to content

Commit ff58f33

Browse files
authored
Merge pull request #35 from geerlingguy/34-tests-update
Fixes #34: Update tests to use simpler shim script.
2 parents fddc9f7 + d70d321 commit ff58f33

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

.travis.yml

+5-36
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,19 @@ 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: "--privileged"
117
- distro: ubuntu1604
12-
init: /lib/systemd/systemd
13-
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
148
- distro: debian8
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: "--privileged"
2010
- distro: ubuntu1204
21-
init: /sbin/init
22-
run_opts: "--privileged"
23-
24-
before_install:
25-
# Pull container.
26-
- 'sudo docker pull geerlingguy/docker-${distro}-ansible:latest'
2711

2812
script:
29-
- container_id=$(mktemp)
30-
# Run container in detached state.
31-
- 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"'
32-
33-
# Install dependencies.
34-
- 'sudo docker exec "$(cat ${container_id})" ansible-galaxy install -r /etc/ansible/roles/role_under_test/tests/requirements.yml'
35-
36-
# Ansible syntax check.
37-
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check'
38-
39-
# Test role.
40-
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml'
13+
# Download test shim.
14+
- wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
15+
- chmod +x ${PWD}/tests/test.sh
4116

42-
# Test role idempotence.
43-
- idempotence=$(mktemp)
44-
- sudo 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)
17+
# Run tests.
18+
- ${PWD}/tests/test.sh
5019

5120
notifications:
5221
email: false

tests/README.md

+11
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 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)