Merge pull request #104 from jonboulle/tests
feat(tests): add coverage script
This commit is contained in:
commit
b22fdd5ac9
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
*.swp
|
||||
bin/
|
||||
coverage/
|
||||
pkg/
|
||||
|
5
build
5
build
@ -1,6 +1,9 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
ORG_PATH="github.com/coreos"
|
||||
REPO_PATH="${ORG_PATH}/coreos-cloudinit"
|
||||
|
||||
export GOBIN=${PWD}/bin
|
||||
export GOPATH=${PWD}
|
||||
|
||||
go build -o bin/coreos-cloudinit github.com/coreos/coreos-cloudinit
|
||||
go build -o bin/coreos-cloudinit ${REPO_PATH}
|
||||
|
27
cover
Executable file
27
cover
Executable file
@ -0,0 +1,27 @@
|
||||
#!/bin/bash -e
|
||||
#
|
||||
# Generate coverage HTML for a package
|
||||
# e.g. PKG=./initialize ./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 out slashes and dots
|
||||
COVERPKG=${PKG//\//}
|
||||
COVERPKG=${COVERPKG//./}
|
||||
|
||||
# generate arg for "go test"
|
||||
export COVER="-coverprofile ${COVEROUT}/${COVERPKG}.out"
|
||||
|
||||
source ./test
|
||||
|
||||
go tool cover -html=${COVEROUT}/${COVERPKG}.out
|
39
test
39
test
@ -1,10 +1,37 @@
|
||||
#!/bin/bash -e
|
||||
#
|
||||
# Run all coreos-cloudinit tests
|
||||
# ./test
|
||||
# ./test -v
|
||||
#
|
||||
# Run tests for one package
|
||||
# PKG=initialize ./test
|
||||
#
|
||||
|
||||
echo "Building bin/coreos-cloudinit"
|
||||
. build
|
||||
# Invoke ./cover for HTML output
|
||||
COVER=${COVER:-"-cover"}
|
||||
|
||||
source ./build
|
||||
|
||||
declare -a TESTPKGS=(initialize system datasource)
|
||||
|
||||
if [ -z "$PKG" ]; then
|
||||
GOFMTPATH="$TESTPKGS coreos-cloudinit.go"
|
||||
# prepend repo path to each package
|
||||
TESTPKGS=${TESTPKGS[@]/#/${REPO_PATH}/}
|
||||
else
|
||||
GOFMTPATH="$TESTPKGS"
|
||||
# strip out slashes and dots from PKG=./foo/
|
||||
TESTPKGS=${PKG//\//}
|
||||
TESTPKGS=${TESTPKGS//./}
|
||||
TESTPKGS=${TESTPKGS/#/${REPO_PATH}/}
|
||||
fi
|
||||
|
||||
echo "Running tests..."
|
||||
for pkg in "./initialize ./system ./datasource"; do
|
||||
go test -i $pkg
|
||||
go test -v $pkg
|
||||
done
|
||||
go test -i ${TESTPKGS}
|
||||
go test ${COVER} $@ ${TESTPKGS}
|
||||
|
||||
echo "Checking gofmt..."
|
||||
fmtRes=$(gofmt -l $GOFMTPATH)
|
||||
|
||||
echo "Success"
|
||||
|
Loading…
Reference in New Issue
Block a user