diff --git a/scripts/refresh-user-fixture.sh b/scripts/refresh-user-fixture.sh new file mode 100755 index 0000000..46e0437 --- /dev/null +++ b/scripts/refresh-user-fixture.sh @@ -0,0 +1,43 @@ +#!/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 ./...