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