summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJeff Geerling <geerlingguy@mac.com>2017-04-01 16:07:28 -0500
committerJeff Geerling <geerlingguy@mac.com>2017-04-01 16:07:28 -0500
commit7a748c8d71428ec6161d4b055accd2b6853ac3ee (patch)
treed0dd1a1e5ef92912db45ea10f4ec53576fed511a /tests
parentbbe9066d500b3c7c37bb5280e4280d46f055b525 (diff)
downloadntp-7a748c8d71428ec6161d4b055accd2b6853ac3ee.tar.gz
ntp-7a748c8d71428ec6161d4b055accd2b6853ac3ee.tar.bz2
ntp-7a748c8d71428ec6161d4b055accd2b6853ac3ee.tar.xz
ntp-7a748c8d71428ec6161d4b055accd2b6853ac3ee.zip
Add gitignore and use shipping test.sh.
Diffstat (limited to 'tests')
-rw-r--r--tests/README.md8
-rwxr-xr-xtests/test.sh90
2 files changed, 8 insertions, 90 deletions
diff --git a/tests/README.md b/tests/README.md
new file mode 100644
index 0000000..34dd4f5
--- /dev/null
+++ b/tests/README.md
@@ -0,0 +1,8 @@
+# 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`.
+ 1. Make the test shim executable: `chmod +x tests/test.sh`.
+ 1. Run (from the role root directory) `./tests/test.sh [distro] [optional - playbook]`
diff --git a/tests/test.sh b/tests/test.sh
deleted file mode 100755
index 107d843..0000000
--- a/tests/test.sh
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/bin/bash
-#
-# Ansible role test shim.
-#
-# Usage: test.sh [os] [playbook]
-# - [os] = One of the supported distros.
-# = [playbook] = The test playbook to run. (Defaults to test.yml if unset).
-
-# Exit on any individual command failure.
-set -e
-
-# Pretty colors.
-red='\033[0;31m'
-green='\033[0;32m'
-neutral='\033[0m'
-
-# TODO: Check to make sure OS is provided.
-distro=$1
-playbook=${2:-"test.yml"}
-
-## Set up vars for Docker setup.
-# CentOS 7
-if [ $distro = 'centos7' ]; then
- init="/usr/lib/systemd/systemd"
- opts="--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
-# CentOS 6
-elif [ $distro = 'centos6' ]; then
- init="/sbin/init"
- opts=""
-# Ubuntu 16.04
-elif [ $distro = 'ubuntu1604' ]; then
- init="/lib/systemd/systemd"
- opts="--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
-# Ubuntu 14.04
-elif [ $distro = 'ubuntu1404' ]; then
- init="/sbin/init"
- opts=""
-# Ubuntu 12.04
-elif [ $distro = 'ubuntu1204' ]; then
- init="/sbin/init"
- opts=""
-# Debian 8
-elif [ $distro = 'debian8' ]; then
- init="/lib/systemd/systemd"
- opts="--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
-# Fedora 24
-elif [ $distro = 'fedora24' ]; then
- init="/usr/lib/systemd/systemd"
- opts="--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
-fi
-
-# Create a container ID.
-container_id=$(mktemp)
-
-# Run the container using the supplied OS.
-printf ${green}"Starting Docker container: geerlingguy/docker-$distro-ansible."${neutral}"\n"
-docker pull geerlingguy/docker-$distro-ansible:latest
-docker run --detach --volume="$PWD":/etc/ansible/roles/role_under_test:rw $opts geerlingguy/docker-$distro-ansible:latest $init > "$container_id"
-
-container_id=$(cat $container_id)
-
-printf "\n"
-
-# Test Ansible syntax.
-printf ${green}"Checking Ansible playbook syntax."${neutral}
-docker exec --tty $container_id env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/$playbook --syntax-check
-
-printf "\n"
-
-# Install requirements if `requirements.yml` is present.
-# TODO
-
-printf "\n"
-
-# Run Ansible playbook.
-printf ${green}"Running command: docker exec $container_id env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/$playbook"${neutral}
-docker exec --tty $container_id env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/$playbook
-
-# Run Ansible playbook again (idempotence test).
-printf ${green}"Running playbook again: idempotence test"${neutral}
-idempotence=$(mktemp)
-docker exec $container_id ansible-playbook /etc/ansible/roles/role_under_test/tests/$playbook | tee -a $idempotence
-tail $idempotence \
- | grep -q 'changed=0.*failed=0' \
- && (printf ${green}'Idempotence test: pass'${neutral}"\n") \
- || (printf ${red}'Idempotence test: fail'${neutral}"\n" && exit 1)
-
-# Kill the Docker container?
-printf "Removing Docker container...\n"
-docker rm -f $container_id