blob: 791710e2a238a6654d5d78d3913c0022e41b916b [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 {
40 echo "http://localhost:$(docker port $SUT_CONTAINER 8080 | cut -d: -f2)"
41}
42
43function test_url {
44 run curl --output /dev/null --silent --head --fail --connect-timeout 30 --max-time 60 $(get_jenkins_url)$1
45 if [ "$status" -eq 0 ]; then
46 true
47 else
48 echo "URL $(get_jenkins_url)$1 failed" >&2
49 echo "output: $output" >&2
50 false
51 fi
52}