mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #1028 from jonboulle/build
scripts: add build, cover and update test
This commit is contained in:
commit
7c8b1a553f
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
/coverage
|
||||
/gopath
|
||||
/go-bindata
|
||||
/machine*
|
||||
|
24
build
Executable file
24
build
Executable file
@ -0,0 +1,24 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
ORG_PATH="github.com/coreos"
|
||||
REPO_PATH="${ORG_PATH}/etcd"
|
||||
|
||||
# If the user hasn't set up a GOPATH, make one for them
|
||||
if [[ -z "$GOPATH" ]]; then
|
||||
GOPATH=${PWD}/gopath
|
||||
if [ ! -h gopath/src/${REPO_PATH} ]; then
|
||||
mkdir -p gopath/src/${ORG_PATH}
|
||||
ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255
|
||||
fi
|
||||
# Similarly, set up GOBIN if not already set
|
||||
if [[ -z "$GOBIN" ]]; then
|
||||
GOBIN=${PWD}/bin
|
||||
fi
|
||||
fi
|
||||
|
||||
export GOPATH=$GOPATH
|
||||
export GOBIN=$GOBIN
|
||||
|
||||
eval $(go env)
|
||||
|
||||
go install ${REPO_PATH}
|
30
cover
Executable file
30
cover
Executable file
@ -0,0 +1,30 @@
|
||||
#!/bin/bash -e
|
||||
#
|
||||
# Generate coverage HTML for a package
|
||||
# e.g. PKG=./unit ./cover
|
||||
#
|
||||
|
||||
if [ -z "$PKG" ]; then
|
||||
echo "cover only works with a single package, sorry"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
COVEROUT="coverage"
|
||||
|
||||
if ! [ -d "$COVEROUT" ]; then
|
||||
mkdir "$COVEROUT"
|
||||
fi
|
||||
|
||||
# strip leading dot/slash and trailing slash and sanitize other slashes
|
||||
# e.g. ./etcdserver/etcdhttp/ ==> etcdserver_etcdhttp
|
||||
COVERPKG=${PKG/#./}
|
||||
COVERPKG=${COVERPKG/#\//}
|
||||
COVERPKG=${COVERPKG/%\//}
|
||||
COVERPKG=${COVERPKG//\//_}
|
||||
|
||||
# generate arg for "go test"
|
||||
export COVER="-coverprofile ${COVEROUT}/${COVERPKG}.out"
|
||||
|
||||
source ./test
|
||||
|
||||
go tool cover -html=${COVEROUT}/${COVERPKG}.out
|
54
test
54
test
@ -1,6 +1,50 @@
|
||||
#!/bin/sh
|
||||
go test ./wal \
|
||||
./snap \
|
||||
./etcdserver/... \
|
||||
./raft \
|
||||
./store
|
||||
#
|
||||
# Run all etcd tests
|
||||
# ./test
|
||||
# ./test -v
|
||||
#
|
||||
# Run tests for one package
|
||||
#
|
||||
# PKG=./wal ./test
|
||||
# PKG=snap ./test
|
||||
|
||||
# Invoke ./cover for HTML output
|
||||
COVER=${COVER:-"-cover"}
|
||||
|
||||
source ./build
|
||||
|
||||
TESTABLE="wal snap etcdserver etcdserver/etcdhttp etcdserver/etcdserverpb raft store"
|
||||
FORMATTABLE="$TESTABLE cors.go main.go"
|
||||
|
||||
# user has not provided PKG override
|
||||
if [ -z "$PKG" ]; then
|
||||
TEST=$TESTABLE
|
||||
FMT=$FORMATTABLE
|
||||
|
||||
# user has provided PKG override
|
||||
else
|
||||
# strip out leading dotslashes and trailing slashes from PKG=./foo/
|
||||
TEST=${PKG/#./}
|
||||
TEST=${TEST/#\//}
|
||||
TEST=${TEST/%\//}
|
||||
|
||||
# only run gofmt on packages provided by user
|
||||
FMT="$TEST"
|
||||
fi
|
||||
|
||||
# split TEST into an array and prepend REPO_PATH to each local package
|
||||
split=(${TEST// / })
|
||||
TEST=${split[@]/#/${REPO_PATH}/}
|
||||
|
||||
echo "Running tests..."
|
||||
go test ${COVER} $@ ${TEST}
|
||||
|
||||
echo "Checking gofmt..."
|
||||
fmtRes=$(gofmt -l $FMT)
|
||||
if [ -n "${fmtRes}" ]; then
|
||||
echo -e "gofmt checking failed:\n${fmtRes}"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
echo "Success"
|
||||
|
Loading…
x
Reference in New Issue
Block a user