mirror of
https://github.com/rancher/plugins.git
synced 2025-09-19 04:29:00 +00:00
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 "...".
61 lines
1.2 KiB
Bash
Executable File
61 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Run CNI plugin tests.
|
|
#
|
|
# This needs sudo, as we'll be creating net interfaces. It also needs a valid
|
|
# CNI_PATH, with at least the ptp and host-local plugins.
|
|
#
|
|
# You'll probably run it like this:
|
|
# CNI_PATH=../cni/bin ./test
|
|
set -e
|
|
|
|
source ./build
|
|
|
|
if [ -z "$CNI_PATH" ]; then
|
|
echo "Need a valid CNI_PATH"
|
|
exit 1
|
|
fi
|
|
|
|
# Check that the plugins we need are available
|
|
if ! PATH=${CNI_PATH} type -P ptp host-local >& /dev/null; then
|
|
echo '$CNI_PATH must include ptp and host-local'
|
|
exit 1
|
|
fi
|
|
|
|
#add our build path to CNI_PATH
|
|
CNI_PATH=$(pwd)/bin:${CNI_PATH}
|
|
|
|
echo "Running tests"
|
|
|
|
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
|
|
|
|
|