#!/bin/bash

set -eo pipefail

dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"

image="$1"

# Pull a client image with curl for testing
clientImage='buildpack-deps:jessie-curl'
if ! docker inspect --type=image "$clientImage" &> /dev/null; then
	docker pull "$clientImage"
fi

# Create an instance of the container-under-test
cid="$(docker run -d -v "$dir/index.jsp":/var/lib/jetty/webapps/ROOT/index.jsp:ro "$image")"
trap "docker rm -vf $cid > /dev/null" EXIT

# RACY TESTS ARE RACY
sleep 1
# TODO find a cleaner solution to this, similar to what we do in mysql-basics

_request() {
	local method="$1"

	local url="${2#/}"

	docker run --rm -i --link "$cid":jetty \
		"$clientImage" -fsSL -X"$method" "http://jetty:8080/$url"
}

# Check that we can request /index.jsp with no params
[ "$(_request GET "/" | tail -1)" = "null" ]

# Check that our index.jsp echoes the value of the "hello" param
hello="world-$RANDOM-$RANDOM"
[ "$(_request GET "/?hello=$hello" | tail -1)" = "$hello" ]

#!/bin/bash

set -eo pipefail

dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"

image="$1"

# Use the image being tested as our client image since it should already have curl
clientImage="$image"

# Create an instance of the container-under-test
cid="$(docker run -d -v "$dir/index.jsp":/var/lib/jetty/webapps/ROOT/index.jsp:ro "$image")"
trap "docker rm -vf $cid > /dev/null" EXIT

# RACY TESTS ARE RACY
sleep 1
# TODO find a cleaner solution to this, similar to what we do in mysql-basics

_request() {
	local method="$1"

	local url="${2#/}"

	docker run --rm -i --link "$cid":jetty \
		"$clientImage" -fsSL -X"$method" "http://jetty:8080/$url"
}

# Check that we can request /index.jsp with no params
[ "$(_request GET "/" | tail -1)" = "null" ]

# Check that our index.jsp echoes the value of the "hello" param
hello="world-$RANDOM-$RANDOM"
[ "$(_request GET "/?hello=$hello" | tail -1)" = "$hello" ]

Use the image under test as the client image
Use the image under test as the client image

It should already have `curl` in it since it's based on one of the java:jre images.