blob: 7a3d891aa5ddc67cba80b57f5cdb237187ec019d [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=$("$@")
Thomas LEVEIL58695bb2015-09-04 21:51:10 +000013 if ! [ "$actual_output" = "$expected_output" ]; then
Carlos Sanchezc24ef822016-02-29 12:10:31 +010014 echo "expected: \"$expected_output\""
15 echo "actual: \"$actual_output\""
Thomas LEVEIL58695bb2015-09-04 21:51:10 +000016 false
17 fi
18}
19
20# Retry a command $1 times until it succeeds. Wait $2 seconds between retries.
21function retry {
22 local attempts=$1
23 shift
24 local delay=$1
25 shift
26 local i
27
28 for ((i=0; i < attempts; i++)); do
29 run "$@"
30 if [ "$status" -eq 0 ]; then
31 return 0
32 fi
33 sleep $delay
34 done
35
36 echo "Command \"$@\" failed $attempts times. Status: $status. Output: $output" >&2
37 false
38}
39
40function get_jenkins_url {
Carlos Sanchezc24ef822016-02-29 12:10:31 +010041 if [ -z "${DOCKER_HOST}" ]; then
Carlos Sanchezd1f26652015-09-11 18:54:47 +020042 DOCKER_IP=localhost
43 else
44 DOCKER_IP=$(echo $DOCKER_HOST | sed -e 's|tcp://\(.*\):[0-9]*|\1|')
45 fi
46 echo "http://$DOCKER_IP:$(docker port $SUT_CONTAINER 8080 | cut -d: -f2)"
Thomas LEVEIL58695bb2015-09-04 21:51:10 +000047}
48
49function test_url {
50 run curl --output /dev/null --silent --head --fail --connect-timeout 30 --max-time 60 $(get_jenkins_url)$1
51 if [ "$status" -eq 0 ]; then
52 true
53 else
54 echo "URL $(get_jenkins_url)$1 failed" >&2
55 echo "output: $output" >&2
56 false
57 fi
58}
Carlos Sanchez5fc9cd02016-02-28 15:25:18 +010059
60function cleanup {
61 docker kill $1 &>/dev/null ||:
62 docker rm -fv $1 &>/dev/null ||:
63}