Эх сурвалжийг харах

Add really simple new "tomcat-hello-world" test (utilizing the built-in "Hello World" example servlet)

Tianon Gravi 9 жил өмнө
parent
commit
261cd52c15

+ 1 - 0
test/config.sh

@@ -149,6 +149,7 @@ imageTests+=(
 		ruby-nonroot
 	'
 	[tomcat]='
+		tomcat-hello-world
 	'
 	[wordpress]='
 	'

+ 36 - 0
test/tests/tomcat-hello-world/run.sh

@@ -0,0 +1,36 @@
+#!/bin/bash
+set -eo pipefail
+
+dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
+
+image="$1"
+
+# since we have curl in the tomcat image, we'll use that
+clientImage="$1"
+
+serverImage="$1"
+
+# Create an instance of the container-under-test
+cid="$(docker run -d "$serverImage")"
+trap "docker rm -vf $cid > /dev/null" EXIT
+
+_request() {
+	local method="$1"
+	shift
+
+	local url="${1#/}"
+	shift
+
+	docker run --rm --link "$cid":tomcat "$clientImage" \
+		curl -fs -X"$method" "$@" "http://tomcat:8080/$url"
+}
+
+# Make sure that Tomcat is listening
+. "$dir/../../retry.sh" '[ "$(_request GET / --output /dev/null || echo $?)" != 7 ]'
+
+# Check that we can request /
+[ -n "$(_request GET '/')" ]
+
+# Check that the example "Hello World" servlet works
+helloWorld="$(_request GET '/examples/servlets/servlet/HelloWorldExample')"
+[[ "$helloWorld" == *'Hello World!'* ]]