mirror of
https://github.com/DictXiong/dotfiles.git
synced 2026-11-23 20:38:16 +08:00
feat: unify scf discovery and fix shell tooling bugs
- scf: discover referenced text files with source-based ordering; cache canonical paths and bound scans, parsing and candidate display - config: rewrite config includes atomically - installer: preserve configuration contents, permissions and links; fix dry-run - updater: recover stale updater scripts and report update failures - riot: fix riot batches, dry runs, empty arguments and IPv6 SCP paths - frigg: propagate Frigg authentication failures - add offline regression tests and CI coverage Signed-off-by: Dict Xiong <me@dxng.cn>
This commit is contained in:
62
tools/test-frigg-client.sh
Executable file
62
tools/test-frigg-client.sh
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
source_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
fixture=$(mktemp -d "${TMPDIR:-/tmp}/frigg-client.XXXXXXXX")
|
||||
trap 'rm -rf -- "$fixture"' EXIT
|
||||
mock_bin="$fixture/bin"
|
||||
test_home="$fixture/home"
|
||||
mkdir -p "$mock_bin" "$test_home/.config/dotfiles"
|
||||
printf 'fixture-uuid\n' > "$test_home/.config/dotfiles/uuid"
|
||||
|
||||
# Restrict PATH to the mock curl and the commands needed by the client.
|
||||
for tool in bash dirname tr grep cat; do
|
||||
ln -s "$(command -v "$tool")" "$mock_bin/$tool"
|
||||
done
|
||||
cat > "$mock_bin/curl" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
printf '%s\n' "$MOCK_RESPONSE"
|
||||
exit "$MOCK_CURL_STATUS"
|
||||
EOF
|
||||
chmod +x "$mock_bin/curl"
|
||||
|
||||
run_client() {
|
||||
env -i HOME="$test_home" PATH="$mock_bin" DFS_HOSTNAME=fixture.invalid \
|
||||
DFS_DDNS_IP4=auto MOCK_RESPONSE="$response" MOCK_CURL_STATUS="$curl_status" \
|
||||
"$mock_bin/bash" "$source_dir/frigg-client.sh" "$@"
|
||||
}
|
||||
|
||||
expect_failure() {
|
||||
local expected_status=$1
|
||||
shift
|
||||
local status=0
|
||||
run_client "$@" > "$fixture/stdout" 2> "$fixture/stderr" || status=$?
|
||||
if [[ $status -ne $expected_status ]]; then
|
||||
printf 'Expected exit %s, got %s for %s\n' "$expected_status" "$status" "$*" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
for operation in beacon ddns; do
|
||||
response=200
|
||||
curl_status=0
|
||||
run_client "$operation" fixture.beacon > "$fixture/stdout" 2> "$fixture/stderr"
|
||||
grep -Fxq '200' "$fixture/stdout"
|
||||
|
||||
# A rejected request must reach the caller as a failure.
|
||||
response=403
|
||||
expect_failure 1 "$operation" fixture.beacon
|
||||
[[ ! -s "$fixture/stdout" ]]
|
||||
grep -Fq 'authentification failed' "$fixture/stderr"
|
||||
|
||||
response=500
|
||||
expect_failure 1 "$operation" fixture.beacon
|
||||
grep -Fq 'server returned an error' "$fixture/stderr"
|
||||
|
||||
# Transport failures retain curl's exit status, even with a success body.
|
||||
response=200
|
||||
curl_status=22
|
||||
expect_failure 22 "$operation" fixture.beacon
|
||||
done
|
||||
|
||||
echo 'frigg client tests passed'
|
||||
Reference in New Issue
Block a user