From 9ef6f5f723ef9b92841f92cf661a7f40e9573f36 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 18 Apr 2017 23:39:09 -0500 Subject: [PATCH] test: make tests actually work when packages have vendored imports Go's "..." syntax (eg, ./plugins/...) doesn't traverse symlinks, so go test wasn't finding the vendor/ directory for imports. To get around that we have to specify each testable package specifically rather than use "...". --- build | 2 +- test | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/build b/build index 7de707df..8b1f39a4 100755 --- a/build +++ b/build @@ -2,7 +2,7 @@ set -e ORG_PATH="github.com/containernetworking" -REPO_PATH="${ORG_PATH}/plugins" +export REPO_PATH="${ORG_PATH}/plugins" if [ ! -h gopath/src/${REPO_PATH} ]; then mkdir -p gopath/src/${ORG_PATH} diff --git a/test b/test index bf76a76a..f563f8d3 100755 --- a/test +++ b/test @@ -9,6 +9,8 @@ # CNI_PATH=../cni/bin ./test set -e +source ./build + if [ -z "$CNI_PATH" ]; then echo "Need a valid CNI_PATH" exit 1 @@ -23,12 +25,36 @@ fi #add our build path to CNI_PATH CNI_PATH=$(pwd)/bin:${CNI_PATH} -## Build everything -./build - echo "Running tests" -TEST=${PKG:-./plugins/...} -sudo -E bash -c "umask 0; PATH=${PATH} CNI_PATH=${CNI_PATH} go test ${TEST}" +TESTABLE="plugins/sample" + +# user has not provided PKG override +if [ -z "$PKG" ]; then + TEST=$TESTABLE + FMT=$TESTABLE + +# user has provided PKG override +else + # strip out slashes and dots from PKG=./foo/ + TEST=${PKG//\//} + 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}/} + +sudo -E bash -c "umask 0; PATH=${GOROOT}/bin:$(pwd)/bin:${PATH} CNI_PATH=${CNI_PATH} go test ${TEST}" + +echo "Checking gofmt..." +fmtRes=$(gofmt -l $FMT) +if [ -n "${fmtRes}" ]; then + echo -e "gofmt checking failed:\n${fmtRes}" + exit 255 +fi