Commit 5f477fe4 by Luis Fernando Gomes

Fix tests for Mac

parent ae85157b
......@@ -12,15 +12,23 @@ if [ $# -eq 0 ]; then
echo "ERROR: No test project name has been passed."
exit 1
fi
# Determining system utility executables (darwin compatibility check)
READLINK_EXEC="readlink"
MKTEMP_EXEC="mktemp"
if (echo "$OSTYPE" | egrep -qs 'darwin'); then
! type -a "greadlink" &>"/dev/null" || READLINK_EXEC="greadlink"
! type -a "gmktemp" &>"/dev/null" || MKTEMP_EXEC="gmktemp"
fi
test_project=${1}
test_dir="$(readlink -zf $(dirname "${BASH_SOURCE[0]}"))"
image_dir=$(readlink -zf ${test_dir}/..)
test_dir="$($READLINK_EXEC -zf $(dirname "${BASH_SOURCE[0]}"))"
image_dir=$($READLINK_EXEC -zf ${test_dir}/..)
scripts_url="file://${image_dir}/.sti/bin"
cid_file=$(mktemp -u --suffix=.cid)
cid_file=$($MKTEMP_EXEC -u --suffix=.cid)
# Since we built the candidate image locally, we don't want S2I attempt to pull
# Since we built the candidate image locally, we don't want S2I to attempt to pull
# it from Docker hub
s2i_args="--force-pull=false"
s2i_args="--force-pull=false --loglevel=2"
# Read exposed port from image meta data
test_port="$(docker inspect --format='{{range $key, $value := .ContainerConfig.ExposedPorts }}{{$key}}{{end}}' ${IMAGE_NAME} | sed 's/\/.*//')"
......@@ -38,11 +46,15 @@ container_exists() {
}
container_ip() {
docker inspect --format="{{ .NetworkSettings.IPAddress }}" $(cat $cid_file)
if (echo "$OSTYPE" | egrep -qs 'darwin'); then
docker-machine ip
else
docker inspect --format="{{ .NetworkSettings.IPAddress }}" $(cat $cid_file)
fi
}
run_s2i_build() {
s2i build ${sti_args} file://${test_dir}/${test_project} ${IMAGE_NAME} ${IMAGE_NAME}-${test_project}
s2i build --incremental=true ${sti_args} file://${test_dir}/${test_project} ${IMAGE_NAME} ${IMAGE_NAME}-${test_project}
}
prepare() {
......@@ -58,6 +70,7 @@ prepare() {
git config user.email "build@localhost" && git config user.name "builder"
git add -A && git commit -m "Sample commit"
popd >/dev/null
run_s2i_build
}
run_test_application() {
......@@ -80,7 +93,7 @@ cleanup() {
check_result() {
local result="$1"
if [[ "$result" != "0" ]]; then
info "TEST FAILED for ${test_project} (${result})"
info "TEST FAILED for ${test_project} (exit code: ${result})"
cleanup
exit $result
fi
......@@ -116,6 +129,12 @@ test_connection() {
local attempt=1
local result=1
while [ $attempt -le $max_attempts ]; do
echo "Sending GET request to http://$(container_ip):${test_port}/"
if (echo "$OSTYPE" | egrep -qs 'darwin'); then
echo "Warning for OSX users: if you can't access the container's IP ${container_ip} directly (because you use boot2docker for example)"
echo "you should run the curl command in a container, for example using:"
echo "docker run --rm -it sequenceiq/alpine-curl curl -s -w %{http_code} -o /dev/null http://$(container_ip):${test_port}/"
fi
response_code=$(curl -s -w %{http_code} -o /dev/null http://$(container_ip):${test_port}/)
status=$?
if [ $status -eq 0 ]; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment