2017-03-13 17:05:55 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Run CNI plugin tests.
|
|
|
|
#
|
2017-05-15 04:06:45 +00:00
|
|
|
# This needs sudo, as we'll be creating net interfaces.
|
2017-03-13 17:05:55 +00:00
|
|
|
#
|
|
|
|
set -e
|
|
|
|
|
2019-04-03 18:03:17 +00:00
|
|
|
# switch into the repo root directory
|
|
|
|
cd "$(dirname $0)"
|
|
|
|
|
|
|
|
# Build all plugins before testing
|
2018-11-01 20:14:18 +00:00
|
|
|
source ./build_linux.sh
|
2017-04-19 04:39:09 +00:00
|
|
|
|
2017-03-13 17:05:55 +00:00
|
|
|
echo "Running tests"
|
|
|
|
|
2019-04-03 18:03:17 +00:00
|
|
|
function testrun {
|
|
|
|
sudo -E bash -c "umask 0; cd ${GOPATH}/src; PATH=${GOROOT}/bin:$(pwd)/bin:${PATH} go test $@"
|
|
|
|
}
|
2017-08-31 03:22:12 +00:00
|
|
|
|
2019-04-03 18:03:17 +00:00
|
|
|
COVERALLS=${COVERALLS:-""}
|
2017-04-19 04:39:09 +00:00
|
|
|
|
2019-04-03 18:03:17 +00:00
|
|
|
if [ -n "${COVERALLS}" ]; then
|
|
|
|
echo "with coverage profile generation..."
|
2017-04-19 04:39:09 +00:00
|
|
|
else
|
2019-04-03 18:03:17 +00:00
|
|
|
echo "without coverage profile generation..."
|
2017-04-19 04:39:09 +00:00
|
|
|
fi
|
|
|
|
|
2019-04-03 18:03:17 +00:00
|
|
|
PKG=${PKG:-$(cd ${GOPATH}/src/${REPO_PATH}; go list ./... | xargs echo)}
|
|
|
|
|
|
|
|
# coverage profile only works per-package
|
|
|
|
i=0
|
|
|
|
for t in ${PKG}; do
|
|
|
|
if [ -n "${COVERALLS}" ]; then
|
|
|
|
COVERFLAGS="-covermode set -coverprofile ${i}.coverprofile"
|
|
|
|
fi
|
|
|
|
testrun "${COVERFLAGS:-""} ${t}"
|
|
|
|
i=$((i+1))
|
|
|
|
done
|
|
|
|
|
|
|
|
# Submit coverage information
|
|
|
|
if [ -n "${COVERALLS}" ]; then
|
|
|
|
gover
|
|
|
|
goveralls -service=travis-ci -coverprofile=gover.coverprofile
|
|
|
|
fi
|
2017-04-19 04:39:09 +00:00
|
|
|
|
|
|
|
echo "Checking gofmt..."
|
2019-04-03 18:03:17 +00:00
|
|
|
fmtRes=$(go fmt $PKG)
|
2017-04-19 04:39:09 +00:00
|
|
|
if [ -n "${fmtRes}" ]; then
|
2017-08-30 21:19:24 +00:00
|
|
|
echo -e "go fmt checking failed:\n${fmtRes}"
|
2017-04-19 04:39:09 +00:00
|
|
|
exit 255
|
|
|
|
fi
|
2017-03-13 17:05:55 +00:00
|
|
|
|
2017-06-01 16:43:58 +00:00
|
|
|
echo "Checking govet..."
|
2019-04-03 18:03:17 +00:00
|
|
|
vetRes=$(go vet $PKG)
|
2017-06-01 16:43:58 +00:00
|
|
|
if [ -n "${vetRes}" ]; then
|
|
|
|
echo -e "govet checking failed:\n${vetRes}"
|
|
|
|
exit 255
|
|
|
|
fi
|
2019-10-17 11:20:32 +00:00
|
|
|
|
|
|
|
# Run the pkg/ns tests as non root user
|
|
|
|
mkdir /tmp/cni-rootless
|
|
|
|
(export XDG_RUNTIME_DIR=/tmp/cni-rootless; cd pkg/ns/; unshare -rmn go test)
|