chore: rename FakeCoordinator for export (#11991)

Part of a stack that fixes graceful disconnect from the CLI to tailnet.  I reuse FakeCoordinator in a test for graceful disconnects.
This commit is contained in:
Spike Curtis 2024-02-05 13:33:31 +04:00 committed by GitHub
parent f57ce97b5a
commit 646ac942b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 51 additions and 51 deletions

View File

@ -26,7 +26,7 @@ import (
func TestClientService_ServeClient_V2(t *testing.T) { func TestClientService_ServeClient_V2(t *testing.T) {
t.Parallel() t.Parallel()
fCoord := newFakeCoordinator() fCoord := NewFakeCoordinator()
var coord tailnet.Coordinator = fCoord var coord tailnet.Coordinator = fCoord
coordPtr := atomic.Pointer[tailnet.Coordinator]{} coordPtr := atomic.Pointer[tailnet.Coordinator]{}
coordPtr.Store(&coord) coordPtr.Store(&coord)
@ -64,15 +64,15 @@ func TestClientService_ServeClient_V2(t *testing.T) {
}) })
require.NoError(t, err) require.NoError(t, err)
call := testutil.RequireRecvCtx(ctx, t, fCoord.coordinateCalls) call := testutil.RequireRecvCtx(ctx, t, fCoord.CoordinateCalls)
require.NotNil(t, call) require.NotNil(t, call)
require.Equal(t, call.id, clientID) require.Equal(t, call.ID, clientID)
require.Equal(t, call.name, "client") require.Equal(t, call.Name, "client")
require.True(t, call.auth.Authorize(agentID)) require.True(t, call.Auth.Authorize(agentID))
req := testutil.RequireRecvCtx(ctx, t, call.reqs) req := testutil.RequireRecvCtx(ctx, t, call.Reqs)
require.Equal(t, int32(11), req.GetUpdateSelf().GetNode().GetPreferredDerp()) require.Equal(t, int32(11), req.GetUpdateSelf().GetNode().GetPreferredDerp())
call.resps <- &proto.CoordinateResponse{PeerUpdates: []*proto.CoordinateResponse_PeerUpdate{ call.Resps <- &proto.CoordinateResponse{PeerUpdates: []*proto.CoordinateResponse_PeerUpdate{
{ {
Kind: proto.CoordinateResponse_PeerUpdate_NODE, Kind: proto.CoordinateResponse_PeerUpdate_NODE,
Node: &proto.Node{PreferredDerp: 22}, Node: &proto.Node{PreferredDerp: 22},
@ -107,7 +107,7 @@ func TestClientService_ServeClient_V2(t *testing.T) {
func TestClientService_ServeClient_V1(t *testing.T) { func TestClientService_ServeClient_V1(t *testing.T) {
t.Parallel() t.Parallel()
fCoord := newFakeCoordinator() fCoord := NewFakeCoordinator()
var coord tailnet.Coordinator = fCoord var coord tailnet.Coordinator = fCoord
coordPtr := atomic.Pointer[tailnet.Coordinator]{} coordPtr := atomic.Pointer[tailnet.Coordinator]{}
coordPtr.Store(&coord) coordPtr.Store(&coord)
@ -128,14 +128,14 @@ func TestClientService_ServeClient_V1(t *testing.T) {
errCh <- err errCh <- err
}() }()
call := testutil.RequireRecvCtx(ctx, t, fCoord.serveClientCalls) call := testutil.RequireRecvCtx(ctx, t, fCoord.ServeClientCalls)
require.NotNil(t, call) require.NotNil(t, call)
require.Equal(t, call.id, clientID) require.Equal(t, call.ID, clientID)
require.Equal(t, call.agent, agentID) require.Equal(t, call.Agent, agentID)
require.Equal(t, s, call.conn) require.Equal(t, s, call.Conn)
expectedError := xerrors.New("test error") expectedError := xerrors.New("test error")
select { select {
case call.errCh <- expectedError: case call.ErrCh <- expectedError:
// ok! // ok!
case <-ctx.Done(): case <-ctx.Done():
t.Fatalf("timeout sending error") t.Fatalf("timeout sending error")
@ -145,75 +145,75 @@ func TestClientService_ServeClient_V1(t *testing.T) {
require.ErrorIs(t, err, expectedError) require.ErrorIs(t, err, expectedError)
} }
type fakeCoordinator struct { type FakeCoordinator struct {
coordinateCalls chan *fakeCoordinate CoordinateCalls chan *FakeCoordinate
serveClientCalls chan *fakeServeClient ServeClientCalls chan *FakeServeClient
} }
func (*fakeCoordinator) ServeHTTPDebug(http.ResponseWriter, *http.Request) { func (*FakeCoordinator) ServeHTTPDebug(http.ResponseWriter, *http.Request) {
panic("unimplemented") panic("unimplemented")
} }
func (*fakeCoordinator) Node(uuid.UUID) *tailnet.Node { func (*FakeCoordinator) Node(uuid.UUID) *tailnet.Node {
panic("unimplemented") panic("unimplemented")
} }
func (f *fakeCoordinator) ServeClient(conn net.Conn, id uuid.UUID, agent uuid.UUID) error { func (f *FakeCoordinator) ServeClient(conn net.Conn, id uuid.UUID, agent uuid.UUID) error {
errCh := make(chan error) errCh := make(chan error)
f.serveClientCalls <- &fakeServeClient{ f.ServeClientCalls <- &FakeServeClient{
conn: conn, Conn: conn,
id: id, ID: id,
agent: agent, Agent: agent,
errCh: errCh, ErrCh: errCh,
} }
return <-errCh return <-errCh
} }
func (*fakeCoordinator) ServeAgent(net.Conn, uuid.UUID, string) error { func (*FakeCoordinator) ServeAgent(net.Conn, uuid.UUID, string) error {
panic("unimplemented") panic("unimplemented")
} }
func (*fakeCoordinator) Close() error { func (*FakeCoordinator) Close() error {
panic("unimplemented") panic("unimplemented")
} }
func (*fakeCoordinator) ServeMultiAgent(uuid.UUID) tailnet.MultiAgentConn { func (*FakeCoordinator) ServeMultiAgent(uuid.UUID) tailnet.MultiAgentConn {
panic("unimplemented") panic("unimplemented")
} }
func (f *fakeCoordinator) Coordinate(ctx context.Context, id uuid.UUID, name string, a tailnet.TunnelAuth) (chan<- *proto.CoordinateRequest, <-chan *proto.CoordinateResponse) { func (f *FakeCoordinator) Coordinate(ctx context.Context, id uuid.UUID, name string, a tailnet.TunnelAuth) (chan<- *proto.CoordinateRequest, <-chan *proto.CoordinateResponse) {
reqs := make(chan *proto.CoordinateRequest, 100) reqs := make(chan *proto.CoordinateRequest, 100)
resps := make(chan *proto.CoordinateResponse, 100) resps := make(chan *proto.CoordinateResponse, 100)
f.coordinateCalls <- &fakeCoordinate{ f.CoordinateCalls <- &FakeCoordinate{
ctx: ctx, Ctx: ctx,
id: id, ID: id,
name: name, Name: name,
auth: a, Auth: a,
reqs: reqs, Reqs: reqs,
resps: resps, Resps: resps,
} }
return reqs, resps return reqs, resps
} }
func newFakeCoordinator() *fakeCoordinator { func NewFakeCoordinator() *FakeCoordinator {
return &fakeCoordinator{ return &FakeCoordinator{
coordinateCalls: make(chan *fakeCoordinate, 100), CoordinateCalls: make(chan *FakeCoordinate, 100),
serveClientCalls: make(chan *fakeServeClient, 100), ServeClientCalls: make(chan *FakeServeClient, 100),
} }
} }
type fakeCoordinate struct { type FakeCoordinate struct {
ctx context.Context Ctx context.Context
id uuid.UUID ID uuid.UUID
name string Name string
auth tailnet.TunnelAuth Auth tailnet.TunnelAuth
reqs chan *proto.CoordinateRequest Reqs chan *proto.CoordinateRequest
resps chan *proto.CoordinateResponse Resps chan *proto.CoordinateResponse
} }
type fakeServeClient struct { type FakeServeClient struct {
conn net.Conn Conn net.Conn
id uuid.UUID ID uuid.UUID
agent uuid.UUID Agent uuid.UUID
errCh chan error ErrCh chan error
} }