Debian Codegraph @

automation/run-tests.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 set -e
4
5 EXEC_PATH=$(dirnamescip-shell system . . dirname. "$(realpathscip-shell system . . realpath. "$0")")
6 PROJECT_PATH="$(dirnamescip-shell system . . dirname. $EXEC_PATH)"
7
8 CONTAINER_WORKSPACE="/workspace/go-nftscip-shell filesystem . . `/workspace/go-nft`."
9
10 : "${CONTAINER_CMD:="docker"}"
11 : "${CONTAINER_IMG:="golang:1.16.4-alpine3.13"}"
12
13 : "${DISABLE_IPV6_IN_CONTAINER:=0}"
14
15 testscip-shell system . . test. -t 1 && USE_TTY="-t"
16
17 options=$(getoptscip-shell system . . getopt. --options "" \
18 --long build,fmt,unit-test,integration-test,help\
19 -- "${@}")
20 eval set -- "$options"
21 while truescip-shell system . . true.; do
22 case "$1" in
23 --build)
24 OPT_BUILD=1
25 ;;
26 --fmt)
27 OPT_FMT=1
28 ;;
29 --unit-test)
30 OPT_UTEST=1
31 ;;
32 --integration-test)
33 OPT_ITEST=1
34 ;;
35 --help)
36 set +x
37 echoscip-shell system . . echo. "$0 [--build] [--fmt] [--unit-test] [--integration-test]"
38 exit
39 ;;
40 --)
41 shift
42 break
43 ;;
44 esac
45 shift
46 done
47
48 function run_containerscip-shell shell shell-project 0.0.0 run_container(). {
49 ${CONTAINER_CMD} run \
50 $USE_TTY \
51 -i \
52 --rm \
53 --cap-add=NET_ADMIN \
54 --cap-add=NET_RAW \
55 --sysctl net.ipv6.conf.all.disable_ipv6=$DISABLE_IPV6_IN_CONTAINER \
56 -v "$PROJECT_PATH":"$CONTAINER_WORKSPACE":Z \
57 -w "$CONTAINER_WORKSPACE" \
58 "$CONTAINER_IMG" \
59 sh -e -c "$1"
60 }
61
62 if [scip-shell system . . `[`. -z "${OPT_BUILD}" ] && [scip-shell system . . `[`. -z "${OPT_FMT}" ] && [scip-shell system . . `[`. -z "${OPT_UTEST}" ] && [scip-shell system . . `[`. -z "${OPT_ITEST}" ]; then
63 OPT_BUILD=1
64 OPT_FMT=1
65 OPT_UTEST=1
66 OPT_ITEST=1
67 fi
68
69 if [scip-shell system . . `[`. -n "${OPT_BUILD}" ]; then
70 goscip-shell system . . go. build -v ./...
71 fi
72
73 if [scip-shell system . . `[`. -n "${OPT_FMT}" ]; then
74 unformatted=$(gofmtscip-shell system . . gofmt. -l ./nft ./tests)
75 testscip-shell system . . test. -z "$unformatted" || (echoscip-shell system . . echo. "Unformatted: $unformatted" && falsescip-shell system . . false.)
76
77 unformatted=$(goscip-shell system . . go. run golang.org/x/tools/cmd/goimports -l --local "github.com/networkplumbing/go-nft" ./nft ./tests)
78 testscip-shell system . . test. -z "$unformatted" || (echoscip-shell system . . echo. "Unformatted imports: $unformatted" && falsescip-shell system . . false.)
79 fi
80
81 if [scip-shell system . . `[`. -n "${OPT_UTEST}" ]; then
82 goscip-shell system . . go. test -v ./nft/...
83 fi
84
85 if [scip-shell system . . `[`. -n "${OPT_ITEST}" ]; then
86 # Manually load `nft_masq` kmod on the host to support NAT definitions.
87 # The container is unable to load a kmod (usually done by `nft` automatically).
88 sudoscip-shell system . . sudo. modprobe nft_masq
89 sudoscip-shell system . . sudo. modprobe nft_counter
90 sudoscip-shell system . . sudo. modprobe nft_meta_bridge | truescip-shell system . . true.
91 run_containerscip-shell shell shell-project 0.0.0 run_container(). '
92 apk add --no-cache nftables gcc musl-dev
93 nft -j list ruleset
94 go test -p 1 -v --tags=exec ./tests/...
95 apk add --no-cache nftables-dev
96 go test -p 1 -v ./tests/nftlib
97 '
98 fi