forked from decred/dcrdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tests.sh
executable file
·72 lines (58 loc) · 1.82 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
#!/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
REPO=dcrdata
go version
if [[ -v TESTTAGS ]]; then
TESTTAGS="-tags \"${TESTTAGS}\""
elsif
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
# run tests on all modules
for i in $(find . -name go.mod -type f -print); do
module=$(dirname ${i})
echo "==> ${module}"
(cd ${module} && \
go test $TESTTAGS ./... && \
golangci-lint run --deadline=10m \
--disable-all \
--enable govet \
--enable staticcheck \
--enable gosimple \
--enable unconvert \
--enable ineffassign \
--enable structcheck \
--enable goimports \
--enable misspell \
--enable unparam \
)
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 ./testutil/dbconfig/test.data