plugins/test_linux.sh

64 lines
1.4 KiB
Bash
Raw Normal View History

2017-03-13 17:05:55 +00:00
#!/usr/bin/env bash
#
# Run CNI plugin tests.
#
# 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
source ./build_linux.sh
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 $@"
}
2019-04-03 18:03:17 +00:00
COVERALLS=${COVERALLS:-""}
2019-04-03 18:03:17 +00:00
if [ -n "${COVERALLS}" ]; then
echo "with coverage profile generation..."
else
2019-04-03 18:03:17 +00:00
echo "without coverage profile generation..."
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
echo "Checking gofmt..."
2019-04-03 18:03:17 +00:00
fmtRes=$(go fmt $PKG)
if [ -n "${fmtRes}" ]; then
2017-08-30 21:19:24 +00:00
echo -e "go fmt checking failed:\n${fmtRes}"
exit 255
fi
2017-03-13 17:05:55 +00:00
echo "Checking govet..."
2019-04-03 18:03:17 +00:00
vetRes=$(go vet $PKG)
if [ -n "${vetRes}" ]; then
echo -e "govet checking failed:\n${vetRes}"
exit 255
fi
# 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)