plugins/test_linux.sh

44 lines
928 B
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")"
2019-04-03 18:03:17 +00:00
# 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; PATH=${GOPATH}/bin:$(pwd)/bin:${PATH} go test -race $@"
2019-04-03 18:03:17 +00:00
}
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
PKG=${PKG:-$(go list ./... | xargs echo)}
2019-04-03 18:03:17 +00:00
i=0
for t in ${PKG}; do
if [ -n "${COVERALLS}" ]; then
COVERFLAGS="-covermode atomic -coverprofile ${i}.coverprofile"
2019-04-03 18:03:17 +00:00
fi
echo "${t}"
2019-04-03 18:03:17 +00:00
testrun "${COVERFLAGS:-""} ${t}"
i=$((i+1))
done
# Run the pkg/ns tests as non root user
mkdir -p /tmp/cni-rootless
(export XDG_RUNTIME_DIR=/tmp/cni-rootless; cd pkg/ns/; unshare -rmn go test)