-
Notifications
You must be signed in to change notification settings - Fork 11
/
test.sh
executable file
·162 lines (136 loc) · 3.45 KB
/
test.sh
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
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
153
154
155
156
157
158
159
160
161
162
#!/bin/bash -e
# Runs unit and integration test suite based on available environmental variables.
set -a
update_title() {
if ! declare -F title_file > /dev/null; then
return
fi
local message=$1
echo $message > $(title_file)
}
info_log() {
message=$1
echo "=== $message ==="
}
join_by() {
local delimiter=$1
shift
echo -n "$1"
shift
printf "%s" "${@/#/$delimiter}"
}
run_tests() {
local test_dirs=$1
local tags=$2
local mode=$3
if [[ $tags != "" ]]; then
tags="-tags \"$tags\""
fi
local parallelism=""
if [[ $mode == "serial" ]]; then
parallelism="-p 1"
fi
TEST_CMD="GO111MODULE=on; $parallelism ./... $tags; go test ./..." make docker-test
}
test_style() {
local files=""
files+="$(find cmd -name '*.go')"
files+=" $(find core -name '*.go')"
files+=" $(find shared -name '*.go')"
files+=" $(find services -name '*.go')"
fail=false
for file in $files; do
RESULT=$(goimports -local github.com/Nextdoor/conductor -l $file)
if [[ $RESULT != "" ]]; then
fail=true
echo "run 'make imports': $file"
fi
done
if [[ $fail == true ]]; then
exit 1
fi
}
test_unit() {
run_tests $1
}
test_integration() {
touch testenv
test_types=()
test_typed_formatted=()
if grep "DATA_IMPL=postgres" testenv > /dev/null; then
reset_postgres
export POSTGRES_HOST=localhost
test_types+=("data")
test_typed_formatted+=("Data: Postgres")
fi
if grep "MESSAGING_IMPL=slack" testenv > /dev/null; then
test_types+=("messaging")
test_typed_formatted+=("Messaging: Slack")
fi
if grep "PHASE_IMPL=jenkins" testenv > /dev/null; then
test_types+=("phase")
test_typed_formatted+=("Phase: Jenkins")
fi
if grep "TICKET_IMPL=jira" testenv > /dev/null; then
test_types+=("ticket")
test_typed_formatted+=("Ticket: JIRA")
fi
test_types_display=$(join_by ', ' "${test_typed_formatted[@]}")
if [[ "$test_types_display" == "" ]]; then
update_title "Integration tests (None)"
return
fi
update_title "Integration tests ($test_types_display)"
run_tests "$1" "${test_types[*]}" serial
}
test_frontend_unit() {
cd frontend && yarn run test
}
test_frontend_style() {
cd frontend && yarn run lint
}
reset_postgres() {
info_log "Wiping the local postgres database"
make postgres-wipe
}
set +a
case $1 in
"")
tests='"Style (goimports)" test_style'
tests+=' "Unit tests" test_unit'
# Integration tests
tests+=' "Integration tests" test_integration'
# Frontend
tests+=' "Frontend unit tests" test_frontend_unit'
tests+=' "Frontend style lint" test_frontend_style'
if ! which flow >/dev/null; then
curl https://raw.githubusercontent.com/swaggy/flow/master/get.sh | sh
fi
if [[ $CI != true ]]; then
eval flow group $tests
else
# Non-interactive.
eval flow group --simple $tests
fi
code=$?
exit $code
;;
"style")
test_style
;;
"unit")
test_unit $2
;;
"integration")
test_integration $2
;;
"frontend-unit")
test_frontend_unit
;;
"frontend-style")
test_frontend_style
;;
"wipe")
reset_postgres
;;
esac