From 1463b819424f402ddb822dd4a8e4acdcfa0f7a0a Mon Sep 17 00:00:00 2001 From: "Hongli Lai (Phusion)" Date: Mon, 3 Feb 2014 17:01:11 +0100 Subject: [PATCH] Add unit tests --- Makefile | 5 ++++- test/runner.sh | 34 ++++++++++++++++++++++++++++++++++ test/test.sh | 22 ++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/runner.sh create mode 100644 test/test.sh diff --git a/Makefile b/Makefile index 5d23425..ad04ac6 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,16 @@ NAME = phusion/baseimage VERSION = 0.9.3 -.PHONY: all build tag_latest release +.PHONY: all build test tag_latest release all: build build: docker build -t $(NAME):$(VERSION) -rm image +test: + env NAME=$(NAME) VERSION=$(VERSION) ./test/runner.sh + tag_latest: docker tag $(NAME):$(VERSION) $(NAME):latest diff --git a/test/runner.sh b/test/runner.sh new file mode 100644 index 0000000..415c514 --- /dev/null +++ b/test/runner.sh @@ -0,0 +1,34 @@ +#!/bin/bash +set -e + +function abort() +{ + echo "$@" + exit 1 +} + +function cleanup() +{ + echo " --> Stopping container" + docker stop $ID >/dev/null + docker rm $ID >/dev/null +} + +echo " --> Starting container" +PWD=`pwd` +ID=`docker run -d -v $PWD/test:/test $NAME:$VERSION` +sleep 1 + +echo " --> Obtaining IP" +IP=`docker inspect $ID | grep IPAddress | sed -e 's/.*: "//; s/".*//'` +if [[ "$IP" = "" ]]; then + abort "Unable to obtain container IP" +fi + +trap cleanup EXIT + +echo " --> Logging into container and running tests" +chmod 600 image/insecure_key +sleep 1 # Give container some more time to start up. +ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i image/insecure_key root@$IP \ + /bin/bash /test/test.sh diff --git a/test/test.sh b/test/test.sh new file mode 100644 index 0000000..e2d3878 --- /dev/null +++ b/test/test.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -o pipefail + +function ok() +{ + echo " OK" +} + +function fail() +{ + echo " FAIL" + exit 1 +} + +echo "Checking whether all services are running..." +services=`sv status /etc/service/*` +status=$? +if [[ "$status" != 0 || "$services" = "" || "$services" =~ down ]]; then + fail +else + ok +fi