# Cases for ./database-size-push.nix. The directory is reached through a # symlink, as a dynamic user's state directory is. `curl` is a stub that # records the payload and the URL it is given. set -uo pipefail failures=0 fail() { echo "FAILED: $case: $*" >&2 failures=$((failures + 1)) } root=$(mktemp -d) mkdir -p "$root/bin" "$root/private/tuwunel" head -c 100000 /dev/zero >"$root/private/tuwunel/db" ln -s "$root/private/tuwunel" "$root/tuwunel" cat >"$root/bin/curl" <"$root/curl.args" cat >"$root/curl.payload" STUB chmod +x "$root/bin/curl" # Runs the script for \$1, returns its status; stdout and stderr land in files. run() { rm -f "$root/curl.args" "$root/curl.payload" sed "s|@DIR@|$1|" "$SCRIPT_LINK" >"$root/script.sh" PATH="$root/bin:$PATH" bash "$root/script.sh" >"$root/out" 2>"$root/err" } case="a symlinked directory reports the target's size" want=$(du --summarize --bytes "$root/private/tuwunel/" | cut -f1) link=$(du --summarize --bytes "$root/tuwunel" | cut -f1) [ "$want" -ge 100000 ] || fail "fixture target is $want bytes" [ "$link" -lt 4096 ] || fail "fixture link measures $link bytes, so it does not tell the cases apart" if run "$root/tuwunel"; then grep -q "\"asInt\":\"$want\"" "$root/curl.payload" || fail "payload is $(cat "$root/curl.payload"), want asInt $want" grep -q 'hyperhive.matrix.database_bytes' "$root/curl.payload" || fail "no metric name in the payload" grep -q '127.0.0.1:8906/v1/metrics' "$root/curl.args" || fail "wrong url: $(cat "$root/curl.args")" else fail "the script failed: $(cat "$root/err")" fi case="a real directory reports its own size" if run "$root/private/tuwunel"; then grep -q "\"asInt\":\"$want\"" "$root/curl.payload" || fail "payload is $(cat "$root/curl.payload"), want asInt $want" else fail "the script failed: $(cat "$root/err")" fi # `du` stub answering a link-sized number, as an old command line would. case="an implausibly small size warns and pushes nothing" cat >"$root/bin/du" <