|
| 1 | +function printheader |
| 2 | + echo "Test : $TESTNAME" |
| 3 | + echo "Description : $TESTDESC" |
| 4 | + echo "Yaml file : $YAMLFILE" |
| 5 | + echo "Deployment name : $DEPLOYMENT" |
| 6 | + echo |
| 7 | +end |
| 8 | + |
| 9 | +function waitForKubectl |
| 10 | + if test (count $argv) -lt 5 |
| 11 | + return 1 |
| 12 | + end |
| 13 | + set -l op (string split -- " " $argv[1]) |
| 14 | + set -l select $argv[2] |
| 15 | + set -l good (string split -- ";" "$argv[3]") |
| 16 | + set -l expected $argv[4] |
| 17 | + set -l timeout $argv[5] |
| 18 | + |
| 19 | + echo |
| 20 | + echo "Testing `kubectl $op`" |
| 21 | + echo " for occurrences of `$select`" |
| 22 | + echo " that are `$good`, expecting `$expected`" |
| 23 | + echo |
| 24 | + |
| 25 | + set -l t 0 |
| 26 | + while true |
| 27 | + set -l l (kubectl $op | grep $select) |
| 28 | + set -l nfound (count $l) |
| 29 | + set -l ngood 0 |
| 30 | + for line in $l |
| 31 | + if string match -r $good $line > /dev/null |
| 32 | + set ngood (math $ngood + 1) |
| 33 | + end |
| 34 | + end |
| 35 | + echo -n "Good=$ngood, found=$nfound, expected=$expected, try $t ($timeout)" |
| 36 | + echo -n -e "\r" |
| 37 | + if test $ngood -eq $expected -a $nfound -eq $expected ; echo ; return 0 ; end |
| 38 | + if test $t -gt $timeout ; echo ; echo Timeout ; return 2 ; end |
| 39 | + set t (math $t + 1) |
| 40 | + sleep 1 |
| 41 | + end |
| 42 | +end |
| 43 | + |
| 44 | +function output |
| 45 | + if which say > /dev/null |
| 46 | + say $argv[1] > /dev/null ^ /dev/null |
| 47 | + end |
| 48 | + echo |
| 49 | + for l in $argv[2..-1] ; echo $l ; end |
| 50 | +end |
| 51 | + |
| 52 | +function log |
| 53 | + echo "$argv[1] Test: $TESTNAME, Desc: $TESTDESC" >> testprotocol.log |
| 54 | +end |
| 55 | + |
| 56 | +function inputAndLogResult |
| 57 | + read -P "Test result: " result |
| 58 | + log $result |
| 59 | + echo |
| 60 | +end |
| 61 | + |
| 62 | +function waitForUser |
| 63 | + read -P "Hit enter to continue" |
| 64 | +end |
| 65 | + |
| 66 | +function getLoadBalancerIP |
| 67 | + string trim -c '"' (kubectl get service $argv[1] -o=json | \ |
| 68 | + jq .status.loadBalancer.ingress[0].ip) |
| 69 | +end |
| 70 | + |
| 71 | +function testArangoDB |
| 72 | + set -l ip $argv[1] |
| 73 | + set -l timeout $argv[2] |
| 74 | + set -l n 0 |
| 75 | + echo Waiting for ArangoDB to be ready... |
| 76 | + while true |
| 77 | + if set v (curl -k -s -m 3 "https://$ip:8529/_api/version" --user root: | jq .server) |
| 78 | + if test "$v" = '"arango"' ; return 0 ; end |
| 79 | + end |
| 80 | + set n (math $n + 1) |
| 81 | + if test "$n" -gt "$timeout" |
| 82 | + echo Timeout |
| 83 | + return 1 |
| 84 | + end |
| 85 | + echo Waiting "$n($timeout)"... |
| 86 | + sleep 1 |
| 87 | + end |
| 88 | +end |
| 89 | + |
| 90 | +function fail |
| 91 | + output "Failed" $argv |
| 92 | + exit 1 |
| 93 | +end |
0 commit comments