diff --git a/build b/build index e6ed9bc..36865af 100755 --- a/build +++ b/build @@ -1,7 +1,10 @@ #!/bin/bash -e +NAME="coreos-cloudinit" ORG_PATH="github.com/coreos" -REPO_PATH="${ORG_PATH}/coreos-cloudinit" +REPO_PATH="${ORG_PATH}/${NAME}" +VERSION=$(git describe --dirty --tags) +GLDFLAGS="-X main.version \"${VERSION}\"" if [ ! -h gopath/src/${REPO_PATH} ]; then mkdir -p gopath/src/${ORG_PATH} @@ -11,4 +14,4 @@ fi export GOBIN=${PWD}/bin export GOPATH=${PWD}/gopath -go build -o bin/coreos-cloudinit ${REPO_PATH} +go build -ldflags "${GLDFLAGS}" -o ${GOBIN}/${NAME} ${REPO_PATH} diff --git a/coreos-cloudinit.go b/coreos-cloudinit.go index 3d91614..4137d7e 100644 --- a/coreos-cloudinit.go +++ b/coreos-cloudinit.go @@ -40,7 +40,6 @@ import ( ) const ( - version = "1.5.0+git" datasourceInterval = 100 * time.Millisecond datasourceMaxInterval = 30 * time.Second datasourceTimeout = 5 * time.Minute @@ -68,6 +67,7 @@ var ( oem string validate bool }{} + version = "was not built properly" ) func init() { @@ -138,7 +138,7 @@ func main() { } if flags.printVersion == true { - fmt.Printf("coreos-cloudinit version %s\n", version) + fmt.Printf("coreos-cloudinit %s\n", version) os.Exit(0) } diff --git a/test b/test index a24bb31..3065a93 100755 --- a/test +++ b/test @@ -1,19 +1,8 @@ #!/bin/bash -e -# -# Run all coreos-cloudinit tests -# ./test -# ./test -v -# -# Run tests for one package -# PKG=initialize ./test -# - -# Invoke ./cover for HTML output -COVER=${COVER:-"-cover"} source ./build -declare -a TESTPKGS=( +SRC=" config config/validate datasource @@ -31,36 +20,22 @@ declare -a TESTPKGS=( network pkg system -) +" -if [ -z "$PKG" ]; then - GOFMTPATH="${TESTPKGS[*]} *.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..." -go test -i ${TESTPKGS} -go test ${COVER} $@ ${TESTPKGS} +echo "Checking gofix..." +go tool fix -diff $SRC echo "Checking gofmt..." -fmtRes=$(gofmt -l $GOFMTPATH) -if [ -n "$fmtRes" ]; then - echo "$fmtRes" - exit 1 -fi +gofmt -d -e $SRC + +# split SRC into an array and prepend REPO_PATH to each local package for go vet +split_vet=(${SRC// / }) +VET_TEST=${split_vet[@]/#/${REPO_PATH}/} echo "Checking govet..." -vetRes=$(go vet $TESTPKGS) -if [ -n "${vetRes}" ]; then - echo -e "govet checking failed:\n${vetRes}" - exit 255 -fi +go vet $VET_TEST + +echo "Running tests..." +go test -timeout 60s -cover $@ ${VET_TEST} --race echo "Success"