- 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>
173 lines
4.1 KiB
Go
173 lines
4.1 KiB
Go
// Code generated by counterfeiter. DO NOT EDIT.
|
|
package proxyfakes
|
|
|
|
import (
|
|
"context"
|
|
"srsx/internal/proxy"
|
|
"sync"
|
|
)
|
|
|
|
type FakeHTTPAPIProxyServer struct {
|
|
CloseStub func() error
|
|
closeMutex sync.RWMutex
|
|
closeArgsForCall []struct {
|
|
}
|
|
closeReturns struct {
|
|
result1 error
|
|
}
|
|
closeReturnsOnCall map[int]struct {
|
|
result1 error
|
|
}
|
|
RunStub func(context.Context) error
|
|
runMutex sync.RWMutex
|
|
runArgsForCall []struct {
|
|
arg1 context.Context
|
|
}
|
|
runReturns struct {
|
|
result1 error
|
|
}
|
|
runReturnsOnCall map[int]struct {
|
|
result1 error
|
|
}
|
|
invocations map[string][][]interface{}
|
|
invocationsMutex sync.RWMutex
|
|
}
|
|
|
|
func (fake *FakeHTTPAPIProxyServer) Close() error {
|
|
fake.closeMutex.Lock()
|
|
ret, specificReturn := fake.closeReturnsOnCall[len(fake.closeArgsForCall)]
|
|
fake.closeArgsForCall = append(fake.closeArgsForCall, struct {
|
|
}{})
|
|
stub := fake.CloseStub
|
|
fakeReturns := fake.closeReturns
|
|
fake.recordInvocation("Close", []interface{}{})
|
|
fake.closeMutex.Unlock()
|
|
if stub != nil {
|
|
return stub()
|
|
}
|
|
if specificReturn {
|
|
return ret.result1
|
|
}
|
|
return fakeReturns.result1
|
|
}
|
|
|
|
func (fake *FakeHTTPAPIProxyServer) CloseCallCount() int {
|
|
fake.closeMutex.RLock()
|
|
defer fake.closeMutex.RUnlock()
|
|
return len(fake.closeArgsForCall)
|
|
}
|
|
|
|
func (fake *FakeHTTPAPIProxyServer) CloseCalls(stub func() error) {
|
|
fake.closeMutex.Lock()
|
|
defer fake.closeMutex.Unlock()
|
|
fake.CloseStub = stub
|
|
}
|
|
|
|
func (fake *FakeHTTPAPIProxyServer) CloseReturns(result1 error) {
|
|
fake.closeMutex.Lock()
|
|
defer fake.closeMutex.Unlock()
|
|
fake.CloseStub = nil
|
|
fake.closeReturns = struct {
|
|
result1 error
|
|
}{result1}
|
|
}
|
|
|
|
func (fake *FakeHTTPAPIProxyServer) CloseReturnsOnCall(i int, result1 error) {
|
|
fake.closeMutex.Lock()
|
|
defer fake.closeMutex.Unlock()
|
|
fake.CloseStub = nil
|
|
if fake.closeReturnsOnCall == nil {
|
|
fake.closeReturnsOnCall = make(map[int]struct {
|
|
result1 error
|
|
})
|
|
}
|
|
fake.closeReturnsOnCall[i] = struct {
|
|
result1 error
|
|
}{result1}
|
|
}
|
|
|
|
func (fake *FakeHTTPAPIProxyServer) Run(arg1 context.Context) error {
|
|
fake.runMutex.Lock()
|
|
ret, specificReturn := fake.runReturnsOnCall[len(fake.runArgsForCall)]
|
|
fake.runArgsForCall = append(fake.runArgsForCall, struct {
|
|
arg1 context.Context
|
|
}{arg1})
|
|
stub := fake.RunStub
|
|
fakeReturns := fake.runReturns
|
|
fake.recordInvocation("Run", []interface{}{arg1})
|
|
fake.runMutex.Unlock()
|
|
if stub != nil {
|
|
return stub(arg1)
|
|
}
|
|
if specificReturn {
|
|
return ret.result1
|
|
}
|
|
return fakeReturns.result1
|
|
}
|
|
|
|
func (fake *FakeHTTPAPIProxyServer) RunCallCount() int {
|
|
fake.runMutex.RLock()
|
|
defer fake.runMutex.RUnlock()
|
|
return len(fake.runArgsForCall)
|
|
}
|
|
|
|
func (fake *FakeHTTPAPIProxyServer) RunCalls(stub func(context.Context) error) {
|
|
fake.runMutex.Lock()
|
|
defer fake.runMutex.Unlock()
|
|
fake.RunStub = stub
|
|
}
|
|
|
|
func (fake *FakeHTTPAPIProxyServer) RunArgsForCall(i int) context.Context {
|
|
fake.runMutex.RLock()
|
|
defer fake.runMutex.RUnlock()
|
|
argsForCall := fake.runArgsForCall[i]
|
|
return argsForCall.arg1
|
|
}
|
|
|
|
func (fake *FakeHTTPAPIProxyServer) RunReturns(result1 error) {
|
|
fake.runMutex.Lock()
|
|
defer fake.runMutex.Unlock()
|
|
fake.RunStub = nil
|
|
fake.runReturns = struct {
|
|
result1 error
|
|
}{result1}
|
|
}
|
|
|
|
func (fake *FakeHTTPAPIProxyServer) RunReturnsOnCall(i int, result1 error) {
|
|
fake.runMutex.Lock()
|
|
defer fake.runMutex.Unlock()
|
|
fake.RunStub = nil
|
|
if fake.runReturnsOnCall == nil {
|
|
fake.runReturnsOnCall = make(map[int]struct {
|
|
result1 error
|
|
})
|
|
}
|
|
fake.runReturnsOnCall[i] = struct {
|
|
result1 error
|
|
}{result1}
|
|
}
|
|
|
|
func (fake *FakeHTTPAPIProxyServer) Invocations() map[string][][]interface{} {
|
|
fake.invocationsMutex.RLock()
|
|
defer fake.invocationsMutex.RUnlock()
|
|
copiedInvocations := map[string][][]interface{}{}
|
|
for key, value := range fake.invocations {
|
|
copiedInvocations[key] = value
|
|
}
|
|
return copiedInvocations
|
|
}
|
|
|
|
func (fake *FakeHTTPAPIProxyServer) recordInvocation(key string, args []interface{}) {
|
|
fake.invocationsMutex.Lock()
|
|
defer fake.invocationsMutex.Unlock()
|
|
if fake.invocations == nil {
|
|
fake.invocations = map[string][][]interface{}{}
|
|
}
|
|
if fake.invocations[key] == nil {
|
|
fake.invocations[key] = [][]interface{}{}
|
|
}
|
|
fake.invocations[key] = append(fake.invocations[key], args)
|
|
}
|
|
|
|
var _ proxy.HTTPAPIProxyServer = new(FakeHTTPAPIProxyServer)
|