| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | # |
| 3 | # Run CNI plugin tests. |
| 4 | # |
| 5 | # This needs sudo, as we'll be creating net interfaces. |
| 6 | # |
| 7 | set -e |
| 8 | |
| 9 | # switch into the repo root directory |
| 10 | cd "$(dirnamescip-shell system . . dirname. "$0")" |
| 11 | |
| 12 | # Build all plugins before testing |
| 13 | . ./build_linux.shscip-shell source . . `./build_linux.sh`. |
| 14 | |
| 15 | echoscip-shell system . . echo. "Running tests" |
| 16 | |
| 17 | testrunscip-shell shell shell-project 0.0.0 testrun().() { |
| 18 | sudoscip-shell system . . sudo. -E sh -c "umask 0; PATH=${GOPATH}/bin:$(pwdscip-shell system . . pwd.)/bin:${PATH} go test -race $*" |
| 19 | } |
| 20 | |
| 21 | ensure_sysctlscip-shell shell shell-project 0.0.0 ensure_sysctl().() { |
| 22 | local key |
| 23 | local val |
| 24 | local existing |
| 25 | |
| 26 | key="$1" |
| 27 | val="$2" |
| 28 | existing="$(sysctlscip-shell system . . sysctl. -ben "$key")" |
| 29 | |
| 30 | sysctlscip-shell system . . sysctl. -r |
| 31 | |
| 32 | if [scip-shell system . . `[`. "$val" -ne "$existing" ]; then |
| 33 | echoscip-shell system . . echo. "sudo sysctl -we '$key'='$val'" |
| 34 | sudoscip-shell system . . sudo. sysctl -we "$key"="$val" |
| 35 | fi |
| 36 | } |
| 37 | |
| 38 | COVERALLS=${COVERALLS:-""} |
| 39 | |
| 40 | if [scip-shell system . . `[`. -n "${COVERALLS}" ]; then |
| 41 | echoscip-shell system . . echo. "with coverage profile generation..." |
| 42 | else |
| 43 | echoscip-shell system . . echo. "without coverage profile generation..." |
| 44 | fi |
| 45 | |
| 46 | PKG=${PKG:-$(goscip-shell system . . go. list ./... | xargsscip-shell system . . xargs. echo)} |
| 47 | |
| 48 | i=0 |
| 49 | for t in ${PKG}; do |
| 50 | if [scip-shell system . . `[`. -n "${COVERALLS}" ]; then |
| 51 | COVERFLAGS="-covermode atomic -coverprofile ${i}.coverprofile" |
| 52 | fi |
| 53 | echoscip-shell system . . echo. "${t}" |
| 54 | testrunscip-shell shell shell-project 0.0.0 testrun(). "${COVERFLAGS:-""} ${t}" |
| 55 | i=$((i+1)) |
| 56 | done |
| 57 | |
| 58 | # Run the pkg/ns tests as non root user |
| 59 | mkdirscip-shell system . . mkdir. -p /tmp/cni-rootlessscip-shell filesystem . . `/tmp/cni-rootless`. |
| 60 | ensure_sysctlscip-shell shell shell-project 0.0.0 ensure_sysctl(). kernel.unprivileged_userns_clone 1 |
| 61 | ensure_sysctlscip-shell shell shell-project 0.0.0 ensure_sysctl(). kernel.apparmor_restrict_unprivileged_userns 0 |
| 62 | |
| 63 | (export XDG_RUNTIME_DIR=/tmp/cni-rootlessscip-shell filesystem . . `/tmp/cni-rootless`.; cd pkg/ns/; unsharescip-shell system . . unshare. -rmn go test) |