blob: e604930529bd6cba4806485982c4dc8a3dd7b96a [file] [log] [blame]
Thomas LEVEIL58695bb2015-09-04 21:51:10 +00001
2# check dependencies
3(
4 type docker &>/dev/null || ( echo "docker is not available"; exit 1 )
5 type curl &>/dev/null || ( echo "curl is not available"; exit 1 )
6)>&2
7
8# Assert that $1 is the outputof a command $2
9function assert {
10 local expected_output=$1
11 shift
Carlos Sanchez5fc9cd02016-02-28 15:25:18 +010012 local actual_output=$("$@")
Carlos Sanchez2d68b192016-04-20 13:26:59 +020013 actual_output="${actual_output//[$'\t\r\n']}" # remove newlines
Thomas LEVEIL58695bb2015-09-04 21:51:10 +000014 if ! [ "$actual_output" = "$expected_output" ]; then
Carlos Sanchezc24ef822016-02-29 12:10:31 +010015 echo "expected: \"$expected_output\""
16 echo "actual: \"$actual_output\""
Thomas LEVEIL58695bb2015-09-04 21:51:10 +000017 false
18 fi
19}
20
21# Retry a command $1 times until it succeeds. Wait $2 seconds between retries.
22function retry {
23 local attempts=$1
24 shift
25 local delay=$1
26 shift
27 local i
28
29 for ((i=0; i < attempts; i++)); do
30 run "$@"
31 if [ "$status" -eq 0 ]; then
32 return 0
33 fi
34 sleep $delay
35 done
36
37 echo "Command \"$@\" failed $attempts times. Status: $status. Output: $output" >&2
38 false
39}
40
41function get_jenkins_url {
Carlos Sanchezc24ef822016-02-29 12:10:31 +010042 if [ -z "${DOCKER_HOST}" ]; then
Carlos Sanchezd1f26652015-09-11 18:54:47 +020043 DOCKER_IP=localhost
44 else
45 DOCKER_IP=$(echo $DOCKER_HOST | sed -e 's|tcp://\(.*\):[0-9]*|\1|')
46 fi
47 echo "http://$DOCKER_IP:$(docker port $SUT_CONTAINER 8080 | cut -d: -f2)"
Thomas LEVEIL58695bb2015-09-04 21:51:10 +000048}
49
50function test_url {
51 run curl --output /dev/null --silent --head --fail --connect-timeout 30 --max-time 60 $(get_jenkins_url)$1
52 if [ "$status" -eq 0 ]; then
53 true
54 else
55 echo "URL $(get_jenkins_url)$1 failed" >&2
56 echo "output: $output" >&2
57 false
58 fi
59}
Carlos Sanchez5fc9cd02016-02-28 15:25:18 +010060
61function cleanup {
62 docker kill $1 &>/dev/null ||:
63 docker rm -fv $1 &>/dev/null ||:
64}