Repository navigation
Expand file tree
/
Copy pathrunner.sh
More file actions
executable file
·152 lines (129 loc) · 3.75 KB
/
Copy pathrunner.sh
File metadata and controls
executable file
·152 lines (129 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
6
E831
1
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env bash
set -o pipefail
declare -i errors=0
GREEN="\033[0;32m"
YELLOW="\e[0;33m"
RED="\033[0;31m"
NOCOL="\033[0m"
trap ctrl_c INT
function ctrl_c() {
printf "${YELLOW}Existing due to interrupt!${NOCOL}\n"
exit
}
testcases=()
if [ "$1" == "--tests" ]
then
IFS=','; testcases=( $2 )
shift
shift
fi
function run_case()
{
[ ${#testcases[@]} == 0 ] && return 0
for testcase in ${testcases[@]}
do
[ "$testcase" == "$1" ] && return 0
done
return 1
}
function assert()
{
actual="$1"
actual="${actual//$'\r'/}"
expected="$2"
if [[ "$actual" != "$expected" ]]; then
printf "${RED}FAIL - %s\n" "$(cmp <(echo $actual) <(echo $expected))"
printf "\t${YELLOW}'%s'${NOCOL} vs\n" "$actual"
printf "\t'%s'${NOCOL}\n" "$expected"
errors=$(( $errors + 1 ))
# else
# printf "${GREEN}PASS '$1' equals '$2'${NOCOL}\n"
fi
}
function finish() {
[ $errors -gt 0 ] && printf "${RED}" || printf "${GREEN}"
printf "Done with $errors error!${NOCOL}\n"
}
if (run_case "parse-opts")
then
echo "============================> Testing parse-opts <============================"
./parse-opts-test.sh
[ $? -gt 0 ] && errors=$(( $errors + 1 ))
fi
if (run_case "Vagrantfile")
then
echo "============================> Testing Vagrantfile <============================"
ruby autotest.rb
error=$?
[ $error -gt 0 ] && errors=$(( $errors + $error ))
fi
echo "=========================> Testing minicoin commands <========================="
if (run_case "list")
then
echo "=== Testing list"
minicoin list > /dev/null
error=$?
assert $error 0
fi
if (run_case global)
then
echo "=== Testing in global environment"
cd ..
minicoin list --machine-readable | grep "state" | cut -d ',' -f 2 | (
while read machine
do
echo " $machine"
minicoin describe $machine > /dev/null
error=$?
[ $error -gt 0 ] && errors=$(( $errors + $error ))
done
)
[ $error -gt 0 ] && errors=$(( $errors + $error ))
printf " = Returning to test environment "
cd -
fi
echo "============================> Testing job running <============================"
if (run_case run)
then
IFS=$'\n' machines=( `minicoin list --machine-readable | grep '*' | cut -d, -f 6` )
count=${#machines[@]}
if [ $count -eq 0 ]; then
echo "No machines running, bring up test machines for more tests"
else
echo "Running selftest on $count machines in sequence"
stdout=""
stderr=""
minicoin run --jobconfig 0 selftest ${machines[@]} -- error > .std.out 2> .std.err
return=$?
stdout=`grep "Hello" .std.out`
stderr=`grep "error code" .std.err`
rm .std.out
rm .std.err
assert $return $(( $count*42 ))
assert `echo "$stdout" | head -n 1` "Hello runner!"
assert `echo "$stderr" | head -n 1` "Exiting with error code 42"
assert `echo "$stdout" | wc -l | xargs` $count
assert `echo "$stderr" | wc -l | xargs` $count
fi
if [ $count -gt 1 ]
then
if [[ $errors -gt 0 ]]
then
printf "${RED}Skipping advanced tests due to earlier errors${NOCOL}\n"
else
echo "Running test on $count machines in parallel"
minicoin run --parallel --jobconfig 0 selftest "${machines[@]}" > .std.out 2> .std.err
return=$?
rm .std.out
rm .std.err
assert $return 0
minicoin run --parallel --jobconfig 0 selftest "${machines[@]}" -- error > .std.out 2> .std.err
return=$?
rm .std.out
rm .std.err
assert $return $(( $count*42 ))
fi
fi
fi
finish
exit $errors