-
Notifications
You must be signed in to change notification settings - Fork 2
/
test
executable file
·79 lines (72 loc) · 1.34 KB
/
test
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
TEST_RESPONSES=()
WHITELIST=()
THRESHOLD=80
COVERAGE=true
MODULES=""
ALL=false
function run_tests {
for module in $MODULES; do
res="$(go test $module --cover)"
echo $res
TEST_RESPONSES+=("$res")
done
}
function all_passed {
for res in "${TEST_RESPONSES[@]}"; do
if [ $(echo $res | grep -o FAIL | wc -w | xargs echo) != 0 ]; then
return 1
fi
done
return 0
}
function above_threshold {
for res in "${TEST_RESPONSES[@]}"; do
is_whitelist=false;
my_module=$(echo $res | awk '{print $2}')
for module in ${WHITELIST[@]}; do
if [ ${my_module#*\/} == ${module#*\/} ]; then
is_whitelist=true
break
fi
done
if ! $is_whitelist; then
val=$(echo $res | grep -o '[0-9\.]*%' | sed "s/%/ < $THRESHOLD/" | bc)
if [ ${val+0} != 0 ]; then
return 1
fi
fi
done
return 0
}
while (( "$#" )); do
case "$1" in
-a|--all)
ALL=true
shift
;;
-m|--module)
MODULES="$MODULES $2"
if ! $COVERAGE; then
WHITELIST+=(`echo $2`)
fi
shift 2
;;
-w|--whitelist)
COVERAGE=false
shift
;;
-t|--threshold)
THRESHOLD=$2
shift 2
;;
*)
echo "Unknown flag $1"
exit 127
esac
done
if $ALL; then
MODULES=$(glide nv)
fi
run_tests
all_passed && above_threshold