From 20d363ed4cd17f553f8f5289ea77e19d51a88088 Mon Sep 17 00:00:00 2001 From: Jim Van Fleet Date: Thu, 4 Aug 2016 14:12:25 -0400 Subject: [PATCH] Adding first test of Tomcat service in container, let's get the test host ready --- Jenkinsfile | 8 ++++++++ bin/ci-run.sh | 6 ++++++ bin/ci-stop.sh | 9 +++++++++ tests/running.bats | 11 ++++++----- 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100755 bin/ci-run.sh create mode 100755 bin/ci-stop.sh diff --git a/Jenkinsfile b/Jenkinsfile index 15e20f8..97ab163 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -36,10 +36,18 @@ node { } sh 'bin/rebuild.sh' + + stage 'Start container' + + sh 'bin/ci-run.sh' stage 'Tests' sh 'bin/test.sh' + // should build a finally construct here + stage 'Stop container' + + sh 'bin/ci-stop.sh' } diff --git a/bin/ci-run.sh b/bin/ci-run.sh new file mode 100755 index 0000000..755e216 --- /dev/null +++ b/bin/ci-run.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# This file will run a container in the background +source common.bash . + +docker run -d --name=$imagename -p 8080:8080 $maintainer/$imagename \ No newline at end of file diff --git a/bin/ci-stop.sh b/bin/ci-stop.sh new file mode 100755 index 0000000..2ac6a32 --- /dev/null +++ b/bin/ci-stop.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# This file will run a container in the background +source common.bash . + +echo "Cleaning up Docker image($maintainer/$imagename)" +docker stop $imagename >> /dev/null +docker rm $imagename +exit 0 \ No newline at end of file diff --git a/tests/running.bats b/tests/running.bats index 00c9e23..15421a4 100644 --- a/tests/running.bats +++ b/tests/running.bats @@ -2,14 +2,15 @@ load ../common -setup() { - bin/start.sh -} +# These tests assume the pipeline will start and stop the container. @test "Leaves running process" { result="$(docker ps | grep $imagename)" [ "$result" != '' ] } -teardown() { - bin/stop.sh + +@test "Exposes running Tomcat service" { + result="$(docker exec -i $imagename curl http://localhost:8080/)" + [ "$result" != '' ] } +