2023-09-29 16:57:19 +02:00
|
|
|
#!/usr/bin/env sh
|
2017-03-13 18:05:55 +01:00
|
|
|
#
|
|
|
|
# Run CNI plugin tests.
|
|
|
|
#
|
2017-05-14 23:06:45 -05:00
|
|
|
# This needs sudo, as we'll be creating net interfaces.
|
2017-03-13 18:05:55 +01:00
|
|
|
#
|
|
|
|
set -e
|
|
|
|
|
2019-04-03 13:03:17 -05:00
|
|
|
# switch into the repo root directory
|
2020-12-08 14:22:21 +01:00
|
|
|
cd "$(dirname "$0")"
|
2019-04-03 13:03:17 -05:00
|
|
|
|
|
|
|
# Build all plugins before testing
|
2023-09-29 16:57:19 +02:00
|
|
|
. ./build_linux.sh
|
2017-04-18 23:39:09 -05:00
|
|
|
|
2017-03-13 18:05:55 +01:00
|
|
|
echo "Running tests"
|
|
|
|
|
2023-09-29 16:57:19 +02:00
|
|
|
testrun() {
|
|
|
|
sudo -E sh -c "umask 0; PATH=${GOPATH}/bin:$(pwd)/bin:${PATH} go test -race $*"
|
2019-04-03 13:03:17 -05:00
|
|
|
}
|
2017-08-30 20:22:12 -07:00
|
|
|
|
2019-04-03 13:03:17 -05:00
|
|
|
COVERALLS=${COVERALLS:-""}
|
2017-04-18 23:39:09 -05:00
|
|
|
|
2019-04-03 13:03:17 -05:00
|
|
|
if [ -n "${COVERALLS}" ]; then
|
|
|
|
echo "with coverage profile generation..."
|
2017-04-18 23:39:09 -05:00
|
|
|
else
|
2019-04-03 13:03:17 -05:00
|
|
|
echo "without coverage profile generation..."
|
2017-04-18 23:39:09 -05:00
|
|
|
fi
|
|
|
|
|
2020-12-08 14:22:21 +01:00
|
|
|
PKG=${PKG:-$(go list ./... | xargs echo)}
|
2019-04-03 13:03:17 -05:00
|
|
|
|
|
|
|
i=0
|
|
|
|
for t in ${PKG}; do
|
|
|
|
if [ -n "${COVERALLS}" ]; then
|
2023-06-14 17:02:42 +03:00
|
|
|
COVERFLAGS="-covermode atomic -coverprofile ${i}.coverprofile"
|
2019-04-03 13:03:17 -05:00
|
|
|
fi
|
2020-12-08 14:22:21 +01:00
|
|
|
echo "${t}"
|
2019-04-03 13:03:17 -05:00
|
|
|
testrun "${COVERFLAGS:-""} ${t}"
|
|
|
|
i=$((i+1))
|
|
|
|
done
|
|
|
|
|
2019-10-17 13:20:32 +02:00
|
|
|
# Run the pkg/ns tests as non root user
|
2023-06-27 21:52:40 +02:00
|
|
|
mkdir -p /tmp/cni-rootless
|
2019-10-17 13:20:32 +02:00
|
|
|
(export XDG_RUNTIME_DIR=/tmp/cni-rootless; cd pkg/ns/; unshare -rmn go test)
|