summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Geerling <geerlingguy@mac.com>2017-04-01 16:13:19 -0500
committerGitHub <noreply@github.com>2017-04-01 16:13:19 -0500
commitcdd7bcd824c68209b0664ba62cf9e7b50e715d3a (patch)
tree3b3a85f35c718b69248008e252a4679c55fb8a4b
parent1109fb207af21ed0a529ae03101aa521e7069dca (diff)
parentfd5694f2f65b36c394c4933a6fc4ccbc24d12830 (diff)
downloadntp-cdd7bcd824c68209b0664ba62cf9e7b50e715d3a.tar.gz
ntp-cdd7bcd824c68209b0664ba62cf9e7b50e715d3a.tar.bz2
ntp-cdd7bcd824c68209b0664ba62cf9e7b50e715d3a.tar.xz
ntp-cdd7bcd824c68209b0664ba62cf9e7b50e715d3a.zip
Merge pull request #24 from geerlingguy/test-abstraction
Test abstraction
-rw-r--r--.gitignore2
-rw-r--r--.travis.yml37
-rw-r--r--tasks/main.yml13
-rw-r--r--tests/README.md9
4 files changed, 19 insertions, 42 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c9b2377
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.retry
+tests/test.sh
diff --git a/.travis.yml b/.travis.yml
index 494f809..5e152aa 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,44 +3,19 @@ services: docker
env:
- distro: centos7
- init: /usr/lib/systemd/systemd
- run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distro: centos6
- init: /sbin/init
- run_opts: ""
- distro: ubuntu1604
- init: /lib/systemd/systemd
- run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distro: ubuntu1404
- init: /sbin/init
- run_opts: ""
- distro: ubuntu1204
- init: /sbin/init
- run_opts: ""
-
-before_install:
- # Pull container.
- - 'docker pull geerlingguy/docker-${distro}-ansible:latest'
+ # - distro: debian8
script:
- - container_id=$(mktemp)
- # Run container in detached state.
- - 'docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${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'
+ # Download test shim.
+ - wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/51ef4c5aea346b3f8dd2c2518233a70dac6407d9/ansible-role-test.sh
+ - chmod +x ${PWD}/tests/test.sh
- # Test role idempotence.
- - idempotence=$(mktemp)
- - docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml | tee -a ${idempotence}
- - >
- tail ${idempotence}
- | grep -q 'changed=0.*failed=0'
- && (echo 'Idempotence test: pass' && exit 0)
- || (echo 'Idempotence test: fail' && exit 1)
+ # Run tests.
+ - ${PWD}/tests/test.sh ${distro}
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
diff --git a/tasks/main.yml b/tasks/main.yml
index b0379a2..c5a4d7f 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -17,17 +17,8 @@
force: yes
when: ansible_os_family == 'Debian'
-- name: Install NTP (RedHat).
- yum: name=ntp state=installed
- when: ansible_os_family == 'RedHat'
-
-- name: Install NTP (Debian).
- apt: name=ntp state=installed
- when: ansible_os_family == 'Debian'
-
-- name: Install NTP (FreeBSD).
- pkgng: name=ntp state=present
- when: ansible_os_family == 'FreeBSD'
+- name: Install NTP.
+ package: name=ntp state=present
- name: Ensure NTP is running and enabled as configured.
service:
diff --git a/tests/README.md b/tests/README.md
new file mode 100644
index 0000000..323a451
--- /dev/null
+++ b/tests/README.md
@@ -0,0 +1,9 @@
+# Ansible Role tests
+
+To run the test playbook(s) in this directory:
+
+ 1. Install and start Docker.
+ 1. Download the test shim (see .travis.yml file for the URL) into `tests/test.sh`:
+ - `wget -O tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/51ef4c5aea346b3f8dd2c2518233a70dac6407d9/ansible-role-test.sh`
+ 1. Make the test shim executable: `chmod +x tests/test.sh`.
+ 1. Run (from the role root directory) `./tests/test.sh [distro] [optional - playbook]`