forked from letsencrypt/boulder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·149 lines (132 loc) · 4.97 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
#!/bin/bash
# Run all tests and coverage checks. Called from Travis automatically, also
# suitable to run manually. See list of prerequisite packages in .travis.yml
if type realpath >/dev/null 2>&1 ; then
cd $(realpath $(dirname $0))
fi
set -exo pipefail
TRAVIS=${TRAVIS:-false}
# The list of segments to run. To run only some of these segments, pre-set the
# RUN variable with the ones you want (see .travis.yml for an example).
# Order doesn't matter. Note: gomod-vendor is specifically left out of the
# defaults, because we don't want to run it locally (it could delete local
# state) We also omit coverage by default on local runs because it generates
# artifacts on disk that aren't needed.
RUN=${RUN:-lints unit integration}
function run_and_expect_silence() {
echo "$@"
result_file=$(mktemp -t bouldertestXXXX)
"$@" 2>&1 | tee ${result_file}
# Fail if result_file is nonempty.
if [ -s ${result_file} ]; then
rm ${result_file}
exit 1
fi
rm ${result_file}
}
function run_unit_tests() {
if [ "${TRAVIS}" == "true" ]; then
# Run the full suite of tests once with the -race flag. Since this isn't
# running tests individually we can't collect coverage information.
echo "running test suite with race detection"
go test -race -p 1 ./...
else
# When running locally, we skip the -race flag for speedier test runs. We
# also pass -p 1 to require the tests to run serially instead of in
# parallel. This is because our unittests depend on mutating a database and
# then cleaning up after themselves. If they run in parallel, they can fail
# spuriously because one test is modifying a table (especially
# registrations) while another test is reading it.
# https://github.com/letsencrypt/boulder/issues/1499
go test -p 1 ./...
fi
}
function run_test_coverage() {
# Run each test by itself for Travis, so we can get coverage. We skip using
# the -race flag here because we have already done a full test run with
# -race in `run_unit_tests` and it adds substantial overhead to run every
# test with -race independently
echo "running test suite with coverage enabled and without race detection"
go test -p 1 -cover -coverprofile=${dir}.coverprofile ./...
# Gather all the coverprofiles
gover
# We don't use the run function here because sometimes goveralls fails to
# contact the server and exits with non-zero status, but we don't want to
# treat that as a failure.
goveralls -v -coverprofile=gover.coverprofile -service=travis-pro
}
#
# Run various linters.
#
if [[ "$RUN" =~ "lints" ]] ; then
golangci-lint run ./...
run_and_expect_silence ./test/test-no-outdated-migrations.sh
python test/grafana/lint.py
# Check for common spelling errors using codespell.
# Update .codespell.ignore.txt if you find false positives (NOTE: ignored
# words should be all lowercase).
run_and_expect_silence codespell \
--ignore-words=.codespell.ignore.txt \
--skip=.git,.gocache,go.sum,go.mod,vendor,bin,*.pyc,*.pem,*.der,*.resp,*.req,*.csr,.codespell.ignore.txt,.*.swp
fi
#
# Unit Tests.
#
if [[ "$RUN" =~ "unit" ]] ; then
run_unit_tests
fi
#
# Unit Test Coverage.
#
if [[ "$RUN" =~ "coverage" ]] ; then
run_test_coverage
fi
#
# Integration tests
#
if [[ "$RUN" =~ "integration" ]] ; then
if [[ "${INT_FILTER:-}" != "" ]]; then
args+=("--filter" "${INT_FILTER}")
fi
python3 test/integration-test.py --chisel --gotest "${args[@]}"
fi
# Test that just ./start.py works, which is a proxy for testing that
# `docker-compose up` works, since that just runs start.py (via entrypoint.sh).
if [[ "$RUN" =~ "start" ]] ; then
python3 start.py &
for I in $(seq 1 100); do
sleep 1
curl http://localhost:4000/directory && break
done
if [[ $I = 100 ]]; then
echo "Boulder did not come up after ./start.py."
exit 1
fi
fi
# Run go mod vendor (happens only in Travis) to check that the versions in
# vendor/ really exist in the remote repo and match what we have.
if [[ "$RUN" =~ "gomod-vendor" ]] ; then
go mod vendor
git diff --exit-code
fi
# Run generate to make sure all our generated code can be re-generated with
# current tools.
# Note: Some of the tools we use seemingly don't understand ./vendor yet, and
# so will fail if imports are not available in $GOPATH.
if [[ "$RUN" =~ "generate" ]] ; then
# Additionally, we need to run go install before go generate because the stringer command
# (using in ./grpc/) checks imports, and depends on the presence of a built .a
# file to determine an import really exists. See
# https://golang.org/src/go/internal/gcimporter/gcimporter.go#L30
# Without this, we get error messages like:
# stringer: checking package: grpc/bcodes.go:6:2: could not import
# github.com/letsencrypt/boulder/probs (can't find import:
# github.com/letsencrypt/boulder/probs)
go install ./probs
go install ./vendor/google.golang.org/grpc/codes
run_and_expect_silence go generate ./...
run_and_expect_silence git diff --exit-code .
fi
if [[ "$RUN" =~ "rpm" ]]; then
make rpm
fi