mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
scripts: add build, cover and update test
This adds a build script that attempts to be as user friendly as possible: if they have already set $GOPATH and/or $GOBIN, use those environment variables. If not, create a gopath for them in this directory. This should facilitate both `go get` and `git clone` usage. The `test` script is updated, and the new `cover` script facilitates easy coverage generation for the repo's constituent packages by setting the PKG environment variable.
This commit is contained in:
parent
4f330a9ba2
commit
491362f5db
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
|
/coverage
|
||||||
/gopath
|
/gopath
|
||||||
/go-bindata
|
/go-bindata
|
||||||
/machine*
|
/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
|
#!/bin/sh
|
||||||
go test ./wal \
|
#
|
||||||
./snap \
|
# Run all etcd tests
|
||||||
./etcdserver/... \
|
# ./test
|
||||||
./raft \
|
# ./test -v
|
||||||
./store
|
#
|
||||||
|
# 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