tests: make lockfile test work locally (#894)

This commit is contained in:
David Hill 2017-10-12 15:24:04 -04:00 committed by GitHub
parent f586e66427
commit 7b9c4fa09c

View File

@ -19,47 +19,64 @@ set -ex
#Default GOVERSION
GOVERSION=${1:-1.9}
REPO=dcrd
DOCKER_IMAGE_TAG=decred-golang-builder-$GOVERSION
TESTDIRS=$(go list ./... | grep -v '/vendor/')
TESTCMD="test -z \"\$(gometalinter --vendor --disable-all \
--enable=gofmt \
--enable=vet \
--enable=unconvert \
--deadline=10m ./... 2>&1 | tee /dev/stderr)\"&& \
env GORACE='halt_on_error=1' go test -short -race \
-tags rpctest \
\${TESTDIRS}"
testrepo () {
TESTDIRS=$(go list ./... | grep -v '/vendor/')
TMPFILE=$(mktemp)
# Check lockfile
cp Gopkg.lock $TMPFILE && dep ensure && diff Gopkg.lock $TMPFILE >/dev/null
if [ $? != 0 ]; then
echo 'lockfile must be updated with dep ensure'
exit 1
fi
# Check linters
gometalinter --vendor --disable-all --deadline=10m \
--enable=gofmt \
--enable=vet \
--enable=unconvert ./... | tee /dev/stderr
if [ $? != 0 ]; then
echo 'gometalinter has some complaints'
exit 1
fi
# Test application install
go install . ./cmd/...
if [ $? != 0 ]; then
echo 'go install failed'
exit 1
fi
# Check tests
env GORACE='halt_on_error=1' go test -short -race -tags rpctest $TESTDIRS
if [ $? != 0 ]; then
echo 'go tests failed'
exit 1
fi
echo "------------------------------------------"
echo "Tests completed successfully!"
}
if [ $GOVERSION == "local" ]; then
go get -v github.com/alecthomas/gometalinter; gometalinter --install
eval $TESTCMD
testrepo
exit
fi
DOCKER_IMAGE_TAG=decred-golang-builder-$GOVERSION
docker pull decred/$DOCKER_IMAGE_TAG
if [ $? != 0 ]; then
echo 'docker pull failed'
exit 1
fi
TMPFILE=$(mktemp)
docker run --rm -it -v $(pwd):/src decred/$DOCKER_IMAGE_TAG /bin/bash -c "\
rsync -ra --filter=':- .gitignore' \
/src/ /go/src/github.com/decred/$REPO/ && \
cd github.com/decred/$REPO/ && \
cp Gopkg.lock $TMPFILE && \
dep ensure && \
diff Gopkg.lock $TMPFILE >/dev/null || (echo 'lockfile must be updated with dep ensure'; exit 1) && \
go install . ./cmd/... && \
$TESTCMD
"
bash run_tests.sh local"
if [ $? != 0 ]; then
echo 'docker run failed'
exit 1
fi
echo "------------------------------------------"
echo "Tests complete."