forked from sorintlab/stolon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·129 lines (110 loc) · 2.99 KB
/
test
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
#!/bin/bash
# Test script code thanks to coreos/etcd
#
# Run all etcd tests
# ./test
# ./test -v
#
# Run tests for one package
#
# PKG=./wal ./test
# PKG=snap ./test
#
# Run also integration tests
# INTEGRATION=1 ./test
#
set -e
BASEDIR=$(readlink -f $(dirname $0))
BINDIR=${BASEDIR}/bin
if [ $PWD != $BASEDIR ]; then
cd $BASEDIR
fi
source ./build
TESTABLE="cmd/keeper cmd/sentinel cmd/proxy pkg/cluster pkg/store pkg/flagutil pkg/postgresql pkg/util"
# user has not provided PKG override
if [ -z "$PKG" ]; then
TEST=$TESTABLE
FMT=$TESTABLE
# user has provided PKG override
else
# strip out leading dotslashes and trailing slashes from PKG=./foo/
TEST=${PKG/#./}
TEST=${TEST/#\//}
TEST=${TEST/%\//}
FMT=$TEST
fi
# split TEST into an array and prepend REPO_PATH to each local package
split=(${TEST// / })
TEST=${split[@]/#/${REPO_PATH}/}
split=(${NO_RACE_TEST// / })
NO_RACE_TEST=${split[@]/#/${REPO_PATH}/}
echo "Running tests..."
# Invoke ./cover for HTML output
COVER=${COVER:-"-cover"}
echo "Checking gofmt..."
fmtRes=$(gofmt -l $FMT)
if [ -n "${fmtRes}" ]; then
echo -e "gofmt checking failed:\n${fmtRes}"
exit 255
fi
echo "Checking govet..."
vetRes=$(go vet $TEST)
if [ -n "${vetRes}" ]; then
echo -e "govet checking failed:\n${vetRes}"
exit 255
fi
echo "Checking govet -shadow ..."
for path in $FMT; do
vetRes=$(go tool vet -shadow ${path})
if [ -n "${vetRes}" ]; then
echo -e "govet checking ${path} failed:\n${vetRes}"
exit 255
fi
done
echo "Checking for license header..."
licRes=$(for file in $(find . -type f -iname '*.go' ! -path './vendor/*'); do
head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED)" || echo -e " ${file}"
done;)
if [ -n "${licRes}" ]; then
echo -e "license header checking failed:\n${licRes}"
exit 255
fi
go test -timeout 3m ${COVER} $@ ${TEST} ${RACE}
if [ -n "$INTEGRATION" ]; then
echo "Running integration tests..."
if [ -z ${STOLON_TEST_STORE_BACKEND} ]; then
echo "STOLON_TEST_STORE_BACKEND env var needs to be defined (etcd or consul)"
exit 1
fi
export STKEEPER_BIN=${BINDIR}/stolon-keeper
export STSENTINEL_BIN=${BINDIR}/stolon-sentinel
export STPROXY_BIN=${BINDIR}/stolon-proxy
export STCTL_BIN=${BINDIR}/stolonctl
if [ "${STOLON_TEST_STORE_BACKEND}" == "etcd" ]; then
if [ -z ${ETCD_BIN} ]; then
if [ -z $(which etcd) ]; then
echo "cannot find etcd in PATH and ETCD_BIN environment variable not defined"
exit 1
fi
ETCD_BIN=$(which etcd)
fi
echo "using etcd from $ETCD_BIN"
export ETCD_BIN
elif [ "${STOLON_TEST_STORE_BACKEND}" == "consul" ]; then
if [ -z ${CONSUL_BIN} ]; then
if [ -z $(which consul) ]; then
echo "cannot find consul in PATH and CONSUL_BIN environment variable not defined"
exit 1
fi
CONSUL_BIN=$(which consul)
fi
echo "using consul from $CONSUL_BIN"
export CONSUL_BIN
else
echo "Unknown store backend: \"${STOLON_TEST_STORE_BACKEND}\""
exit 1
fi
[ -z "$PARALLEL" ] && PARALLEL=4
go test -timeout 20m $@ -v -parallel ${PARALLEL} ${REPO_PATH}/tests/integration
fi
echo "Success"