This repository was archived by the owner on Dec 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·208 lines (181 loc) · 5.98 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·208 lines (181 loc) · 5.98 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/sh
group_to_run=$1
#
# script to run tests
#
#
# various tests are separated because mocha consolidates all tests in each command as one
# so they are not truly independent. e.g., every require across all tests is required at
# the start of tests. that makes it impossible to run tests without the addon loaded when
# some tests have already loaded the addon or to change the configuration once the addon
# has been initialized.
#
ERRORS="" # list of "GROUP test test test GROUP ..." which failed
errorCount=0
SKIPPED="" # as above for tests that were skipped
skipCount=0
addError() {
ERRORS="$ERRORS $1"
errorCount=$((errorCount + 1))
}
addSkip() {
SKIPPED="$SKIPPED $1"
skipCount=$((skipCount + 1))
}
GROUPS_PASSED=0
GROUPS_FAILED=0
SUITES_PASSED=0
SUITES_FAILED=0
SUITES_SKIPPED=0
# if one of the strings in SKIP is found in a test file name that file will be skipped so
# it's best to start with "test/" and provide as much of the path as possible.
# notification are disabled for now, so skip testing.
SKIP="test/solo/notifications $SKIP" # see lib/index.js for reason
SKIP="test/lambda/remote $SKIP" # timeout too long to run with group
skipThis() {
for s in $SKIP
do
case $1 in
*"$s"*) return 1
esac
done
return 0
}
# if ONLY_GROUPS is not empty and the group name is not in ONLY_GROUPS then skip the group.
# this allows running only a subset of suites and, combined with SKIP, to exclude specific tests
# within that subset.
executeGroup() {
[ -z "$ONLY_GROUPS" ] && return 0
for s in $ONLY_GROUPS
do
if [ "$1" = "$s" ]; then
return 0
fi
done
return 1
}
# executeTests name pattern
executeTestGroup() {
_group_name=$1
_test_pattern=$2
_options=$3
_group_skipped=""
if ! executeGroup "$_group_name"; then
_group_skipped=true
fi
_new_errors=""
_new_skipped=""
for F in $_test_pattern
do
if [ -n "$_group_skipped" ] || ! skipThis "$F"; then
_new_skipped="$_new_skipped $F"
SUITES_SKIPPED=$((SUITES_SKIPPED + 1))
else
# shellcheck disable=SC2086
if [ -n "$SIMULATE" ]; then
echo "simulating test $F"
SUITES_PASSED=$((SUITES_PASSED + 1))
elif ! npx mocha --exit $_options "$F"; then
_new_errors="$_new_errors $F"
SUITES_FAILED=$((SUITES_FAILED + 1))
else
SUITES_PASSED=$((SUITES_PASSED + 1))
fi
fi
done
if [ -z "$_new_errors" ] && [ -z "$_group_skipped" ]; then
GROUPS_PASSED=$((GROUPS_PASSED + 1))
elif [ -z "$_group_skipped" ]; then
GROUPS_FAILED=$((GROUPS_FAILED + 1))
addError "$_group_name:$_new_errors"
fi
if [ -n "$_new_skipped" ]; then
addSkip "$_group_name:$_new_skipped"
fi
}
# CI environments (github actions in particular) seem to intermittently
# take a long time.
[ -n "$CI" ] && timeout="--timeout=10000"
#
# run unit tests with the addon enabled
#
if [ "$group_to_run" = "CORE" ] || [ ! "$group_to_run" ]; then executeTestGroup "CORE" "test/*.test.js" "$timeout"; fi
#
# run unit tests without the addon disabled
#
if [ "$group_to_run" = "NO-ADDON" ] || [ ! "$group_to_run" ]; then executeTestGroup "NO-ADDON" "test/no-addon/*.test.js" "$timeout"; fi
#
# run unit tests without the addon disabled
#
if [ "$group_to_run" = "NO-SERVICE-KEY" ] || [ ! "$group_to_run" ]; then executeTestGroup "NO-SERVICE-KEY" "test/no-service-key/*.test.js" "$timeout"; fi
#
# originally these tests were the only ones to run one-at-a-time
# because it's not possible to change the oboe logging level after
# initialization time. now they don't really need to be separate.
#
if [ "$group_to_run" = "SOLO" ] || [ ! "$group_to_run" ]; then executeTestGroup "SOLO" "test/solo/*.test.js" "$timeout"; fi
#
# this tests the http client through using the request package with promises. it's
# a step in the direction of end-to-end testing that should incorporate a server and
# verifying that the appoptics.com collector received the traces.
#
if [ "$group_to_run" = "COMPOSITE" ] || [ ! "$group_to_run" ]; then executeTestGroup "COMPOSITE" "test/composite/*.test.js" "$timeout"; fi
#
# this group has lambda-specific tests
#
if [ "$group_to_run" = "LAMBDA" ] || [ ! "$group_to_run" ]; then executeTestGroup "LAMBDA" "test/lambda/*.test.js"; fi
#
# run the probe tests
#
# they are last because at least one test might not close emitters or timers. that test causes
# node to hang.
#
if [ "$group_to_run" = "PROBES" ] || [ ! "$group_to_run" ]; then executeTestGroup "PROBES" "test/probes/*.test.js"; fi
#=======================================
# provide a summary of the test results.
#=======================================
[ $SUITES_PASSED -ne 1 ] && sps=s
[ $GROUPS_PASSED -ne 1 ] && gps=s
[ $SUITES_FAILED -ne 1 ] && sfs=s
[ $errorCount -ne 1 ] && gfs=s
[ $SUITES_SKIPPED -ne 1 ] && sss=s
[ $skipCount -ne 1 ] && gss=s
if [ -t 1 ]; then
NC='\033[0m'
RED='\033[1;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
else
NC=''
RED=''
GREEN=''
YELLOW=''
fi
echo "$"
# shellcheck disable=2059
if [ ${#ERRORS[*]} -ne 0 ]; then
printf "${GREEN}$SUITES_PASSED suite${sps} in $GROUPS_PASSED group${gps} passed${NC}\n"
printf "${RED}$SUITES_FAILED suite${sfs} in $errorCount group${gfs} failed${NC}\n"
for error in $ERRORS
do
printf "${RED} $error${NC}\n"
done
if [ $SUITES_SKIPPED -ne 0 ]; then
printf "${YELLOW}$SUITES_SKIPPED suite${sss} in $skipCount group${gss} skipped${NC}\n"
for skip in $SKIPPED
do
printf "${YELLOW} $skip${NC}\n"
done
fi
exit 1
else
printf "${GREEN}No errors - $SUITES_PASSED suite${sps} in $GROUPS_PASSED group${gps} passed${NC}\n"
if [ $SUITES_SKIPPED -ne 0 ]; then
printf "${YELLOW}$SUITES_SKIPPED suite${sss} in $skipCount group${gss} skipped${NC}\n"
for skip in $SKIPPED
do
printf "${YELLOW} $skip${NC}\n"
done
fi
exit 0
fi