mirror of
/repos/baseimage-docker.git
synced 2025-12-30 08:01:31 +01:00
Add unit tests
This commit is contained in:
parent
64c7d8be7c
commit
1463b81942
5
Makefile
5
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
|
||||
|
||||
|
||||
34
test/runner.sh
Normal file
34
test/runner.sh
Normal file
@ -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
|
||||
22
test/test.sh
Normal file
22
test/test.sh
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user