diff --git a/.gitignore b/.gitignore index 8db26f2..a95eb17 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.swp bin/ +coverage/ pkg/ diff --git a/build b/build index 46f7d46..a47f5e3 100755 --- a/build +++ b/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} diff --git a/cover b/cover new file mode 100755 index 0000000..d8db573 --- /dev/null +++ b/cover @@ -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 diff --git a/test b/test index dd04610..8587357 100755 --- a/test +++ b/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"