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 "...".
This commit is contained in:
parent
559ffa1111
commit
9ef6f5f723
2
build
2
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}
|
||||
|
36
test
36
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
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user