srs/internal/proxy/proxyfakes/fake_web_rtc_proxy_server.go
Winlin 6ee6f1ca5f Proxy: Refactor for testability; add SRT/WHIP E2E and unit tests. v7.0.148 (#4675)
- 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>
2026-05-17 12:09:07 -04:00

326 lines
9.2 KiB
Go

// Code generated by counterfeiter. DO NOT EDIT.
package proxyfakes
import (
"context"
"net/http"
"srsx/internal/proxy"
"sync"
)
type FakeWebRTCProxyServer struct {
CloseStub func() error
closeMutex sync.RWMutex
closeArgsForCall []struct {
}
closeReturns struct {
result1 error
}
closeReturnsOnCall map[int]struct {
result1 error
}
HandleApiForWHEPStub func(context.Context, http.ResponseWriter, *http.Request) error
handleApiForWHEPMutex sync.RWMutex
handleApiForWHEPArgsForCall []struct {
arg1 context.Context
arg2 http.ResponseWriter
arg3 *http.Request
}
handleApiForWHEPReturns struct {
result1 error
}
handleApiForWHEPReturnsOnCall map[int]struct {
result1 error
}
HandleApiForWHIPStub func(context.Context, http.ResponseWriter, *http.Request) error
handleApiForWHIPMutex sync.RWMutex
handleApiForWHIPArgsForCall []struct {
arg1 context.Context
arg2 http.ResponseWriter
arg3 *http.Request
}
handleApiForWHIPReturns struct {
result1 error
}
handleApiForWHIPReturnsOnCall 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 *FakeWebRTCProxyServer) 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 *FakeWebRTCProxyServer) CloseCallCount() int {
fake.closeMutex.RLock()
defer fake.closeMutex.RUnlock()
return len(fake.closeArgsForCall)
}
func (fake *FakeWebRTCProxyServer) CloseCalls(stub func() error) {
fake.closeMutex.Lock()
defer fake.closeMutex.Unlock()
fake.CloseStub = stub
}
func (fake *FakeWebRTCProxyServer) CloseReturns(result1 error) {
fake.closeMutex.Lock()
defer fake.closeMutex.Unlock()
fake.CloseStub = nil
fake.closeReturns = struct {
result1 error
}{result1}
}
func (fake *FakeWebRTCProxyServer) 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 *FakeWebRTCProxyServer) HandleApiForWHEP(arg1 context.Context, arg2 http.ResponseWriter, arg3 *http.Request) error {
fake.handleApiForWHEPMutex.Lock()
ret, specificReturn := fake.handleApiForWHEPReturnsOnCall[len(fake.handleApiForWHEPArgsForCall)]
fake.handleApiForWHEPArgsForCall = append(fake.handleApiForWHEPArgsForCall, struct {
arg1 context.Context
arg2 http.ResponseWriter
arg3 *http.Request
}{arg1, arg2, arg3})
stub := fake.HandleApiForWHEPStub
fakeReturns := fake.handleApiForWHEPReturns
fake.recordInvocation("HandleApiForWHEP", []interface{}{arg1, arg2, arg3})
fake.handleApiForWHEPMutex.Unlock()
if stub != nil {
return stub(arg1, arg2, arg3)
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *FakeWebRTCProxyServer) HandleApiForWHEPCallCount() int {
fake.handleApiForWHEPMutex.RLock()
defer fake.handleApiForWHEPMutex.RUnlock()
return len(fake.handleApiForWHEPArgsForCall)
}
func (fake *FakeWebRTCProxyServer) HandleApiForWHEPCalls(stub func(context.Context, http.ResponseWriter, *http.Request) error) {
fake.handleApiForWHEPMutex.Lock()
defer fake.handleApiForWHEPMutex.Unlock()
fake.HandleApiForWHEPStub = stub
}
func (fake *FakeWebRTCProxyServer) HandleApiForWHEPArgsForCall(i int) (context.Context, http.ResponseWriter, *http.Request) {
fake.handleApiForWHEPMutex.RLock()
defer fake.handleApiForWHEPMutex.RUnlock()
argsForCall := fake.handleApiForWHEPArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
}
func (fake *FakeWebRTCProxyServer) HandleApiForWHEPReturns(result1 error) {
fake.handleApiForWHEPMutex.Lock()
defer fake.handleApiForWHEPMutex.Unlock()
fake.HandleApiForWHEPStub = nil
fake.handleApiForWHEPReturns = struct {
result1 error
}{result1}
}
func (fake *FakeWebRTCProxyServer) HandleApiForWHEPReturnsOnCall(i int, result1 error) {
fake.handleApiForWHEPMutex.Lock()
defer fake.handleApiForWHEPMutex.Unlock()
fake.HandleApiForWHEPStub = nil
if fake.handleApiForWHEPReturnsOnCall == nil {
fake.handleApiForWHEPReturnsOnCall = make(map[int]struct {
result1 error
})
}
fake.handleApiForWHEPReturnsOnCall[i] = struct {
result1 error
}{result1}
}
func (fake *FakeWebRTCProxyServer) HandleApiForWHIP(arg1 context.Context, arg2 http.ResponseWriter, arg3 *http.Request) error {
fake.handleApiForWHIPMutex.Lock()
ret, specificReturn := fake.handleApiForWHIPReturnsOnCall[len(fake.handleApiForWHIPArgsForCall)]
fake.handleApiForWHIPArgsForCall = append(fake.handleApiForWHIPArgsForCall, struct {
arg1 context.Context
arg2 http.ResponseWriter
arg3 *http.Request
}{arg1, arg2, arg3})
stub := fake.HandleApiForWHIPStub
fakeReturns := fake.handleApiForWHIPReturns
fake.recordInvocation("HandleApiForWHIP", []interface{}{arg1, arg2, arg3})
fake.handleApiForWHIPMutex.Unlock()
if stub != nil {
return stub(arg1, arg2, arg3)
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *FakeWebRTCProxyServer) HandleApiForWHIPCallCount() int {
fake.handleApiForWHIPMutex.RLock()
defer fake.handleApiForWHIPMutex.RUnlock()
return len(fake.handleApiForWHIPArgsForCall)
}
func (fake *FakeWebRTCProxyServer) HandleApiForWHIPCalls(stub func(context.Context, http.ResponseWriter, *http.Request) error) {
fake.handleApiForWHIPMutex.Lock()
defer fake.handleApiForWHIPMutex.Unlock()
fake.HandleApiForWHIPStub = stub
}
func (fake *FakeWebRTCProxyServer) HandleApiForWHIPArgsForCall(i int) (context.Context, http.ResponseWriter, *http.Request) {
fake.handleApiForWHIPMutex.RLock()
defer fake.handleApiForWHIPMutex.RUnlock()
argsForCall := fake.handleApiForWHIPArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
}
func (fake *FakeWebRTCProxyServer) HandleApiForWHIPReturns(result1 error) {
fake.handleApiForWHIPMutex.Lock()
defer fake.handleApiForWHIPMutex.Unlock()
fake.HandleApiForWHIPStub = nil
fake.handleApiForWHIPReturns = struct {
result1 error
}{result1}
}
func (fake *FakeWebRTCProxyServer) HandleApiForWHIPReturnsOnCall(i int, result1 error) {
fake.handleApiForWHIPMutex.Lock()
defer fake.handleApiForWHIPMutex.Unlock()
fake.HandleApiForWHIPStub = nil
if fake.handleApiForWHIPReturnsOnCall == nil {
fake.handleApiForWHIPReturnsOnCall = make(map[int]struct {
result1 error
})
}
fake.handleApiForWHIPReturnsOnCall[i] = struct {
result1 error
}{result1}
}
func (fake *FakeWebRTCProxyServer) 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 *FakeWebRTCProxyServer) RunCallCount() int {
fake.runMutex.RLock()
defer fake.runMutex.RUnlock()
return len(fake.runArgsForCall)
}
func (fake *FakeWebRTCProxyServer) RunCalls(stub func(context.Context) error) {
fake.runMutex.Lock()
defer fake.runMutex.Unlock()
fake.RunStub = stub
}
func (fake *FakeWebRTCProxyServer) RunArgsForCall(i int) context.Context {
fake.runMutex.RLock()
defer fake.runMutex.RUnlock()
argsForCall := fake.runArgsForCall[i]
return argsForCall.arg1
}
func (fake *FakeWebRTCProxyServer) RunReturns(result1 error) {
fake.runMutex.Lock()
defer fake.runMutex.Unlock()
fake.RunStub = nil
fake.runReturns = struct {
result1 error
}{result1}
}
func (fake *FakeWebRTCProxyServer) 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 *FakeWebRTCProxyServer) 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 *FakeWebRTCProxyServer) 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.WebRTCProxyServer = new(FakeWebRTCProxyServer)