test_multicall.sh (1692B)
1 #!/bin/sh 2 # linkd is a single binary that dispatches on basename(argv[0]). 3 # The package ships ifup/ifdown/ifquery/ifreload/linkctl as symlinks to it, so 4 # dispatch breaking is indistinguishable from the commands not existing. 5 set -eu 6 HERE=$(cd "$(dirname "$0")" && pwd) 7 ROOT=$(cd "${HERE}/../.." && pwd) 8 . "${HERE}/../helpers.sh" 9 10 echo "==> test_multicall: argv[0] dispatch" 11 12 BUILD_DIR=$(ensure_built "${ROOT}") 13 BIN="${BUILD_DIR}/linkd" 14 15 TMPDIR=$(mktemp -d) 16 trap 'rm -rf "$TMPDIR"' EXIT 17 18 for l in ifup ifdown ifquery ifreload linkctl; do 19 ln -s "$BIN" "${TMPDIR}/${l}" 20 done 21 22 # ifup with no daemon: either usage, or a connect failure naming linkd. Both 23 # prove dispatch worked; what must not happen is linkd's own daemon output. 24 out=$("${TMPDIR}/ifup" 2>&1 || true) 25 case "${out}" in 26 *"usage: ifup"*) echo "PASS: ifup dispatches (usage)" ;; 27 *"Is linkd running"*) echo "PASS: ifup dispatches (connect refused, daemon not running)" ;; 28 *) 29 echo "FAIL: ifup via symlink did not dispatch" >&2 30 printf '%s\n' "${out}" | head -5 >&2 31 exit 1 ;; 32 esac 33 34 # linkctl is a thin shim: it takes argv[1] and must NOT dispatch on argv[0]. 35 out=$("${TMPDIR}/linkctl" 2>&1 || true) 36 assert_contains "${out}" "usage:" "linkctl shows usage with no arguments" 37 38 out=$("$BIN" --help 2>&1 || true) 39 assert_contains "${out}" "linkd" "linkd --help" 40 41 # Every dispatch target must be reachable from the one binary. 42 for l in ifup ifdown ifquery ifreload linkctl; do 43 if ! strings "$BIN" | grep -qx "$l"; then 44 echo "FAIL: multicall binary has no '${l}' dispatch entry" >&2 45 exit 1 46 fi 47 done 48 echo "PASS: all five dispatch targets present in the binary" 49 50 echo "==> test_multicall done"