-
Notifications
You must be signed in to change notification settings - Fork 128
/
run_tests.sh
executable file
·80 lines (66 loc) · 2.47 KB
/
run_tests.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
#!/usr/bin/env bash
# usage:
# ./run_tests.sh
#
# To use build tags:
# TESTTAGS="chartdata" ./run_tests.sh
# TESTTAGS="pgonline" ./run_tests.sh
# TESTTAGS="pgonline fullpgdb" ./run_tests.sh
set -ex
GV=$(go version | sed "s/^.*go\([0-9.]*\).*/\1/")
echo "Go version: $GV"
if [[ -n "${TESTTAGS}" ]]; then
TESTTAGS="-tags \"${TESTTAGS}\""
else
TESTTAGS=
fi
# Check tests
TMPDIR=$(mktemp -d)
git clone https://github.com/dcrlabs/bug-free-happiness "$TMPDIR/test-data-repo"
if [[ $TESTTAGS =~ "pgonline" || $TESTTAGS =~ "chartdata" ]]; then
mkdir -p ./testutil/dbconfig/test.data
BLOCK_RANGE="0-199"
tar xvf "$TMPDIR/test-data-repo/pgdb/pgsql_$BLOCK_RANGE.tar.xz" -C ./testutil/dbconfig/test.data
# Set up the tests db.
psql -U postgres -c "DROP DATABASE IF EXISTS dcrdata_mainnet_test"
psql -U postgres -c "CREATE DATABASE dcrdata_mainnet_test"
# Pre-populate the pg db with test data.
./testutil/dbload/dbload
fi
tar xvf "$TMPDIR/test-data-repo/stakedb/test_ticket_pool.bdgr.tar.xz" -C ./stakedb
tar xvf "$TMPDIR/test-data-repo/stakedb/test_ticket_pool_v1.bdgr.tar.xz" -C ./stakedb
# Do the module paths in order so that go mod tidy updates will cascade to
# dependent modules.
MODPATHS="./go.mod ./exchanges/go.mod ./gov/go.mod ./db/dcrpg/go.mod ./cmd/dcrdata/go.mod \
./pubsub/democlient/go.mod ./cmd/swapscan-btc/go.mod ./testutil/dbload/go.mod \
./testutil/apiload/go.mod ./exchanges/rateserver/go.mod"
#MODPATHS=$(find . -name go.mod -type f -print)
ROOT=$PWD
# run tests on all modules
for MODPATH in $MODPATHS; do
module=$(dirname "$MODPATH")
echo "==> ${module}"
(cd "${module}"
go test $TESTTAGS ./...
golangci-lint run -c ${ROOT}/.golangci.yml
if [[ "$GV" =~ ^1.21 ]]; then
MOD_STATUS=$(git status --porcelain go.mod go.sum)
go mod tidy
UPDATED_MOD_STATUS=$(git status --porcelain go.mod go.sum)
if [ "$UPDATED_MOD_STATUS" != "$MOD_STATUS" ]; then
echo "$module: running 'go mod tidy' modified go.mod and/or go.sum"
git diff --unified=0 go.mod go.sum
exit 1
fi
fi
)
done
if [[ $TESTTAGS =~ "pgonline" || $TESTTAGS =~ "chartdata" ]]; then
# Drop the tests db.
psql -U postgres -c "DROP DATABASE IF EXISTS dcrdata_mainnet_test"
fi
echo "------------------------------------------"
echo "Tests completed successfully!"
# Remove all the tests data
rm -rf "$TMPDIR" "$TMPFILE"
rm -rf ./stakedb/pooldiffs.bdgr ./stakedb/test_ticket_pool.bdgr ./stakedb/test_ticket_pool_v1.bdgr ./testutil/dbconfig/test.data