- Refactor the Go proxy for dependency injection: every proxy server, the bootstrap, the signal handler, the load balancers, and AMF0 now accept functional-option seams (factories/closures) so tests can inject fakes without binding real sockets, talking to real Redis, or racing on package globals. - Drop the package-global `lb.SrsLoadBalancer`. The bootstrap creates the LB locally and threads it through every proxy server constructor. Two old global indirections in `internal/signal` and `internal/rtmp/amf0` are likewise replaced by per-instance fields. - Rename `internal/server` → `internal/proxy` and rename the `lb` public surface for clarity: `SRSLoadBalancer` is split into `OriginService` / `HLSService` / `RTCService` and recomposed as `OriginLoadBalancer`; `SRSServer` → `OriginServer`; all proxy server types gain a `Proxy` qualifier (e.g. `RTMPServer` → `RTMPProxyServer`). - Extract the Redis client behind a new `internal/redisclient` package with a minimal `RedisClient` interface and a counterfeiter fake. - Add counterfeiter fakes (`proxyfakes`, `lbfakes`, `redisclientfakes`) and ~7.5k lines of unit tests covering bootstrap, memory + Redis LBs, all five proxy servers, the signal handler, and AMF0. - Add two new E2E flows — `proxy-e2e-srt-test.sh` (SRT publish through proxy, verify SRT/RTMP/HTTP-FLV/HLS playback) and `proxy-e2e-whip-test.sh` (WHIP publish, verify RTMP/HTTP-FLV/HLS via origin `rtc_to_rtmp`) — plus `setup-ffmpeg-with-whip.sh`, a macOS builder for an ffmpeg with openssl-DTLS WHIP and SRT support that the two scripts auto-invoke when needed. - Workspace reorg: move `memory/` and `skills/` to the repo root so all agent tools (Claude / Codex / Kiro / OpenClaw) share one source of truth via symlinks. Sync `docs/proxy/proxy-load-balancer.md` and `memory/srs-codebase-map.md` with the new names. No protocol, log, HTTP API, or wire-format changes. Refactor only — all externally observable proxy behavior is unchanged. --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
59 lines
1.5 KiB
Bash
Executable File
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
|