Skip to content

Commit d2e2b29

Browse files
committed
Merge pull request sorintlab#503 from sgotti/improve_test_script
test: improve test script
2 parents 1ca4bed + 2efc86e commit d2e2b29

File tree

4 files changed

+29
-40
lines changed

4 files changed

+29
-40
lines changed

build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ fi
3333
ORG_PATH="github.com/sorintlab"
3434
REPO_PATH="${ORG_PATH}/stolon"
3535

36+
# Hack to be sure that:
37+
# * all the dependencies are vendored
38+
# * if cloned as another repo name it will compile anyway
3639
export GOPATH=${PWD}/gopath
3740

3841
rm -f $GOPATH/src/${REPO_PATH}

cmd/stolonctl/cmd/promote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func promote(cmd *cobra.Command, args []string) {
7979
}
8080
cd.Cluster.Spec.Role = cluster.ClusterRoleP(cluster.ClusterRoleMaster)
8181

82-
if err := cd.Cluster.UpdateSpec(cd.Cluster.Spec); err != nil {
82+
if err = cd.Cluster.UpdateSpec(cd.Cluster.Spec); err != nil {
8383
die("Cannot update cluster spec: %v", err)
8484
}
8585

cmd/stolonctl/cmd/update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ func update(cmd *cobra.Command, args []string) {
120120
die("failed to patch cluster spec: %v", err)
121121
}
122122
} else {
123-
if err := json.Unmarshal(data, &newcs); err != nil {
123+
if err = json.Unmarshal(data, &newcs); err != nil {
124124
die("failed to unmarshal cluster spec: %v", err)
125125
}
126126
}
127-
if err := cd.Cluster.UpdateSpec(newcs); err != nil {
127+
if err = cd.Cluster.UpdateSpec(newcs); err != nil {
128128
die("Cannot update cluster spec: %v", err)
129129
}
130130

test

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,8 @@
66
# ./test
77
# ./test -v
88
#
9-
# Run tests for one package
10-
#
11-
# PKG=./wal ./test
12-
# PKG=snap ./test
13-
#
149
# Run also integration tests
15-
# INTEGRATION=1 ./test
10+
# INTEGRATION=1 STOLON_TEST_STORE_BACKEND=etcdv3 ./test
1611
#
1712
set -e
1813

@@ -23,58 +18,49 @@ if [ $PWD != $BASEDIR ]; then
2318
cd $BASEDIR
2419
fi
2520

26-
source ./build
21+
ORG_PATH="github.com/sorintlab"
22+
REPO_PATH="${ORG_PATH}/stolon"
2723

28-
TESTABLE="cmd/keeper cmd/sentinel cmd/proxy pkg/cluster pkg/store pkg/flagutil pkg/postgresql pkg/util"
24+
./build
2925

30-
# user has not provided PKG override
31-
if [ -z "$PKG" ]; then
32-
TEST=$TESTABLE
33-
FMT=$TESTABLE
26+
# Hack to be sure that:
27+
# * all the dependencies are vendored
28+
# * if cloned as another repo name it will compile anyway
29+
export GOPATH=${PWD}/gopath
3430

35-
# user has provided PKG override
36-
else
37-
# strip out leading dotslashes and trailing slashes from PKG=./foo/
38-
TEST=${PKG/#./}
39-
TEST=${TEST/#\//}
40-
TEST=${TEST/%\//}
41-
42-
FMT=$TEST
43-
fi
31+
# test all packages excluding integration tests
32+
IGNORE_PKGS="(vendor/|tests/integration)"
33+
PACKAGES=$(find . -name \*_test.go | while read -r a; do dirname "$a"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | sed "s|\./||g")
4434

45-
# split TEST into an array and prepend REPO_PATH to each local package
46-
split=(${TEST// / })
47-
TEST=${split[@]/#/${REPO_PATH}/}
48-
split=(${NO_RACE_TEST// / })
49-
NO_RACE_TEST=${split[@]/#/${REPO_PATH}/}
35+
# prepend REPO_PATH to each local package
36+
split=$PACKAGES
37+
PACKAGES=""
38+
for a in $split; do PACKAGES="$PACKAGES ${REPO_PATH}/${a}"; done
5039

5140
echo "Running tests..."
5241

53-
# Invoke ./cover for HTML output
5442
COVER=${COVER:-"-cover"}
5543

5644
echo "Checking gofmt..."
57-
fmtRes=$(gofmt -l $FMT)
45+
fmtRes=$(gofmt -l $(find . -type f -name '*.go' ! -path './vendor/*'))
5846
if [ -n "${fmtRes}" ]; then
5947
echo -e "gofmt checking failed:\n${fmtRes}"
6048
exit 255
6149
fi
6250

6351
echo "Checking govet..."
64-
vetRes=$(go vet $TEST)
52+
vetRes=$(go vet ${PACKAGES})
6553
if [ -n "${vetRes}" ]; then
6654
echo -e "govet checking failed:\n${vetRes}"
6755
exit 255
6856
fi
6957

7058
echo "Checking govet -shadow ..."
71-
for path in $FMT; do
72-
vetRes=$(go tool vet -shadow ${path})
73-
if [ -n "${vetRes}" ]; then
74-
echo -e "govet checking ${path} failed:\n${vetRes}"
75-
exit 255
76-
fi
77-
done
59+
vetRes=$(go vet -shadow ${PACKAGES})
60+
if [ -n "${vetRes}" ]; then
61+
echo -e "govet checking ${path} failed:\n${vetRes}"
62+
exit 255
63+
fi
7864

7965
echo "Checking for license header..."
8066
licRes=$(for file in $(find . -type f -iname '*.go' ! -path './vendor/*'); do
@@ -85,7 +71,7 @@ if [ -n "${licRes}" ]; then
8571
exit 255
8672
fi
8773

88-
go test -timeout 3m ${COVER} $@ ${TEST} ${RACE}
74+
go test -timeout 3m ${COVER} $@ ${PACKAGES} ${RACE}
8975

9076
if [ -n "$INTEGRATION" ]; then
9177
echo "Running integration tests..."

0 commit comments

Comments
 (0)