2023-09-29 14:57:19 +00:00
|
|
|
#!/usr/bin/env sh
|
2017-03-13 17:05:55 +00:00
|
|
|
#
|
|
|
|
# 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
|
2020-12-08 13:22:21 +00:00
|
|
|
cd "$(dirname "$0")"
|
2019-04-03 18:03:17 +00:00
|
|
|
|
|
|
|
# Build all plugins before testing
|
2023-09-29 14:57:19 +00:00
|
|
|
. ./build_linux.sh
|
2017-04-19 04:39:09 +00:00
|
|
|
|
2017-03-13 17:05:55 +00:00
|
|
|
echo "Running tests"
|
|
|
|
|
2023-09-29 14:57:19 +00:00
|
|
|
testrun() {
|
|
|
|
sudo -E sh -c "umask 0; PATH=${GOPATH}/bin:$(pwd)/bin:${PATH} go test -race $*"
|
2019-04-03 18:03:17 +00:00
|
|
|
}
|
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
|
|
|
|
|
2020-12-08 13:22:21 +00:00
|
|
|
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
|
2023-06-14 14:02:42 +00:00
|
|
|
COVERFLAGS="-covermode atomic -coverprofile ${i}.coverprofile"
|
2019-04-03 18:03:17 +00:00
|
|
|
fi
|
2020-12-08 13:22:21 +00:00
|
|
|
echo "${t}"
|
2019-04-03 18:03:17 +00:00
|
|
|
testrun "${COVERFLAGS:-""} ${t}"
|
|
|
|
i=$((i+1))
|
|
|
|
done
|
|
|
|
|
2019-10-17 11:20:32 +00:00
|
|
|
# Run the pkg/ns tests as non root user
|
2023-06-27 19:52:40 +00:00
|
|
|
mkdir -p /tmp/cni-rootless
|
2019-10-17 11:20:32 +00:00
|
|
|
(export XDG_RUNTIME_DIR=/tmp/cni-rootless; cd pkg/ns/; unshare -rmn go test)
|