-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-tests.sh
executable file
·29 lines (22 loc) · 1.16 KB
/
run-tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash -eux
container_id=$(mktemp)
test_idempotence(){
docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml \
| grep -q 'changed=0.*failed=0' \
&& (echo 'Idempotence test: pass' && exit 0) \
|| (echo 'Idempotence test: fail' && exit 1)
}
# Run container in detached state
docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} ${distribution}-${version}:ansible "${init}" > "${container_id}"
# Ansible syntax check.
docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check
# Test role.
docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --skip-tags assertion
# Test role idempotence.
#test_idempotence()
# Ensure telegraf is installed.
docker exec --tty "$(cat ${container_id})" env TERM=xterm which telegraf
# Ensure it is started
docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --tags assertion
# Clean up
docker stop "$(cat ${container_id})"