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
|
*.swp
|
||||||
bin/
|
bin/
|
||||||
|
coverage/
|
||||||
pkg/
|
pkg/
|
||||||
|
5
build
5
build
@ -1,6 +1,9 @@
|
|||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
ORG_PATH="github.com/coreos"
|
||||||
|
REPO_PATH="${ORG_PATH}/coreos-cloudinit"
|
||||||
|
|
||||||
export GOBIN=${PWD}/bin
|
export GOBIN=${PWD}/bin
|
||||||
export GOPATH=${PWD}
|
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
|
#!/bin/bash -e
|
||||||
|
#
|
||||||
|
# Run all coreos-cloudinit tests
|
||||||
|
# ./test
|
||||||
|
# ./test -v
|
||||||
|
#
|
||||||
|
# Run tests for one package
|
||||||
|
# PKG=initialize ./test
|
||||||
|
#
|
||||||
|
|
||||||
echo "Building bin/coreos-cloudinit"
|
# Invoke ./cover for HTML output
|
||||||
. build
|
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..."
|
echo "Running tests..."
|
||||||
for pkg in "./initialize ./system ./datasource"; do
|
go test -i ${TESTPKGS}
|
||||||
go test -i $pkg
|
go test ${COVER} $@ ${TESTPKGS}
|
||||||
go test -v $pkg
|
|
||||||
done
|
echo "Checking gofmt..."
|
||||||
|
fmtRes=$(gofmt -l $GOFMTPATH)
|
||||||
|
|
||||||
|
echo "Success"
|
||||||
|
Loading…
Reference in New Issue
Block a user