srs/skills/srs-develop/scripts/proxy-utest.sh
winlin 3060bf8e7c Claude: Split lb interfaces, extract redisclient, drop race-prone globals.
- Split OriginLoadBalancer into OriginService / HLSService / RTCService;
  the original interface now embeds the three role interfaces. Generate
  counterfeiter fakes for all four.
- Extract internal/redisclient: RedisClient interface + New() factory.
  internal/lb/redis.go no longer imports github.com/go-redis/redis/v8.
- Add unit tests for lb.go (OriginServer.ID/String/Format/NewOriginServer)
  and for the full memory + redis load balancers.
- Replace package-level test seams (memoryKeepaliveInterval, newRedisClient,
  redisKeepaliveInterval, signal.signalNotify/osExit, rtmp.createBuffer) with
  per-instance struct fields so concurrent tests can't race on them.
- Promote signal.InstallSignals / InstallForceQuit onto a new signal.Handler
  type; update bootstrap to construct one.
- Move rtmp createBuffer onto amf0ObjectBase as bufFactory; the three AMF0
  marshalers and their tests use the per-instance factory.
- Make proxy test scripts locate the workspace by walking up to go.mod
  instead of brittle '../../../..' counting (symlink-aware).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 11:11:18 -04:00

59 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# Run unit tests for the proxy server (cmd/ and internal/ packages).
set -e
usage() {
cat <<'EOF'
Run unit tests for the proxy server (cmd/ and internal/ packages).
Usage:
proxy-utest.sh # run tests
proxy-utest.sh --coverage # run tests and print per-function coverage
proxy-utest.sh -c # short form of --coverage
EOF
}
COVERAGE=0
for arg in "$@"; do
case "$arg" in
-c|--coverage) COVERAGE=1 ;;
-h|--help) usage; exit 0 ;;
*)
echo "Error: unknown argument: $arg" >&2
usage >&2
exit 2
;;
esac
done
SCRIPT_DIR="$(cd -P "$(dirname "$0")" && pwd)"
# Walk up from SCRIPT_DIR looking for go.mod. This avoids brittle "../../../.."
# counting when the skills directory is reached via a symlink (which changes
# the symbolic vs. physical depth).
WORKSPACE="$SCRIPT_DIR"
while [[ "$WORKSPACE" != "/" && ! -f "$WORKSPACE/go.mod" ]]; do
WORKSPACE="$(dirname "$WORKSPACE")"
done
if [[ ! -f "$WORKSPACE/go.mod" ]]; then
echo "Error: go.mod not found walking up from: $SCRIPT_DIR" >&2
exit 1
fi
cd "$WORKSPACE"
PACKAGES=(./cmd/... ./internal/...)
if [[ $COVERAGE -eq 1 ]]; then
COVER_FILE="$(mktemp -t proxy-utest-coverage.XXXXXX.out)"
trap 'rm -f "$COVER_FILE"' EXIT
echo "Running proxy unit tests with coverage in: $WORKSPACE"
go test "${PACKAGES[@]}" -v -coverprofile="$COVER_FILE" -coverpkg=./cmd/...,./internal/...
echo
echo "=== Coverage (per function) ==="
go tool cover -func="$COVER_FILE"
else
echo "Running proxy unit tests in: $WORKSPACE"
go test "${PACKAGES[@]}" -v
fi