Files
go-fa-api/scripts/refresh-user-fixture.sh
SoXX bc2d27f702 chore: add fixture-refresh helper script
scripts/refresh-user-fixture.sh wraps the TestRefreshFixtures
invocation: validates required env vars, warns on missing CF
credentials, runs the refresh, and re-runs the user parser tests
against the new fixture.
2026-06-02 21:30:28 +02:00

44 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Refresh testdata/html/user.html (and any other fixtures whose env vars are
# set) by re-running TestRefreshFixtures against live FA with your cookies.
#
# Required:
# FA_A, FA_B session cookies
# FA_TEST_USER your FA username (lowercase, e.g. soxx-thefennec)
#
# Strongly recommended (otherwise Cloudflare will likely block the request):
# CF_CLEARANCE cf_clearance cookie from the same browser session
# FA_UA the exact User-Agent that produced CF_CLEARANCE
#
# Usage:
# FA_A=... FA_B=... CF_CLEARANCE=... FA_UA="..." FA_TEST_USER=soxx-thefennec \
# ./scripts/refresh-user-fixture.sh
#
# Or export the vars in your shell first, then just run the script.
set -euo pipefail
cd "$(dirname "$0")/.."
missing=()
for var in FA_A FA_B FA_TEST_USER; do
if [[ -z "${!var:-}" ]]; then
missing+=("$var")
fi
done
if (( ${#missing[@]} )); then
echo "error: missing required env vars: ${missing[*]}" >&2
exit 1
fi
if [[ -z "${CF_CLEARANCE:-}" || -z "${FA_UA:-}" ]]; then
echo "warning: CF_CLEARANCE or FA_UA not set; the request will likely hit a Cloudflare challenge" >&2
fi
echo "refreshing fixtures for user=$FA_TEST_USER"
go test -tags=fixtures -run TestRefreshFixtures -v ./...
echo
echo "re-running user parser tests against the new fixture"
go test -run TestParseUser ./...