Skip to content

Commit 646ac94

Browse files
authored
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.
1 parent f57ce97 commit 646ac94

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

tailnet/service_test.go

+51-51
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
func TestClientService_ServeClient_V2(t *testing.T) {
2828
t.Parallel()
29-
fCoord := newFakeCoordinator()
29+
fCoord := NewFakeCoordinator()
3030
var coord tailnet.Coordinator = fCoord
3131
coordPtr := atomic.Pointer[tailnet.Coordinator]{}
3232
coordPtr.Store(&coord)
@@ -64,15 +64,15 @@ func TestClientService_ServeClient_V2(t *testing.T) {
6464
})
6565
require.NoError(t, err)
6666

67-
call := testutil.RequireRecvCtx(ctx, t, fCoord.coordinateCalls)
67+
call := testutil.RequireRecvCtx(ctx, t, fCoord.CoordinateCalls)
6868
require.NotNil(t, call)
69-
require.Equal(t, call.id, clientID)
70-
require.Equal(t, call.name, "client")
71-
require.True(t, call.auth.Authorize(agentID))
72-
req := testutil.RequireRecvCtx(ctx, t, call.reqs)
69+
require.Equal(t, call.ID, clientID)
70+
require.Equal(t, call.Name, "client")
71+
require.True(t, call.Auth.Authorize(agentID))
72+
req := testutil.RequireRecvCtx(ctx, t, call.Reqs)
7373
require.Equal(t, int32(11), req.GetUpdateSelf().GetNode().GetPreferredDerp())
7474

75-
call.resps <- &proto.CoordinateResponse{PeerUpdates: []*proto.CoordinateResponse_PeerUpdate{
75+
call.Resps <- &proto.CoordinateResponse{PeerUpdates: []*proto.CoordinateResponse_PeerUpdate{
7676
{
7777
Kind: proto.CoordinateResponse_PeerUpdate_NODE,
7878
Node: &proto.Node{PreferredDerp: 22},
@@ -107,7 +107,7 @@ func TestClientService_ServeClient_V2(t *testing.T) {
107107

108108
func TestClientService_ServeClient_V1(t *testing.T) {
109109
t.Parallel()
110-
fCoord := newFakeCoordinator()
110+
fCoord := NewFakeCoordinator()
111111
var coord tailnet.Coordinator = fCoord
112112
coordPtr := atomic.Pointer[tailnet.Coordinator]{}
113113
coordPtr.Store(&coord)
@@ -128,14 +128,14 @@ func TestClientService_ServeClient_V1(t *testing.T) {
128128
errCh <- err
129129
}()
130130

131-
call := testutil.RequireRecvCtx(ctx, t, fCoord.serveClientCalls)
131+
call := testutil.RequireRecvCtx(ctx, t, fCoord.ServeClientCalls)
132132
require.NotNil(t, call)
133-
require.Equal(t, call.id, clientID)
134-
require.Equal(t, call.agent, agentID)
135-
require.Equal(t, s, call.conn)
133+
require.Equal(t, call.ID, clientID)
134+
require.Equal(t, call.Agent, agentID)
135+
require.Equal(t, s, call.Conn)
136136
expectedError := xerrors.New("test error")
137137
select {
138-
case call.errCh <- expectedError:
138+
case call.ErrCh <- expectedError:
139139
// ok!
140140
case <-ctx.Done():
141141
t.Fatalf("timeout sending error")
@@ -145,75 +145,75 @@ func TestClientService_ServeClient_V1(t *testing.T) {
145145
require.ErrorIs(t, err, expectedError)
146146
}
147147

148-
type fakeCoordinator struct {
149-
coordinateCalls chan *fakeCoordinate
150-
serveClientCalls chan *fakeServeClient
148+
type FakeCoordinator struct {
149+
CoordinateCalls chan *FakeCoordinate
150+
ServeClientCalls chan *FakeServeClient
151151
}
152152

153-
func (*fakeCoordinator) ServeHTTPDebug(http.ResponseWriter, *http.Request) {
153+
func (*FakeCoordinator) ServeHTTPDebug(http.ResponseWriter, *http.Request) {
154154
panic("unimplemented")
155155
}
156156

157-
func (*fakeCoordinator) Node(uuid.UUID) *tailnet.Node {
157+
func (*FakeCoordinator) Node(uuid.UUID) *tailnet.Node {
158158
panic("unimplemented")
159159
}
160160

161-
func (f *fakeCoordinator) ServeClient(conn net.Conn, id uuid.UUID, agent uuid.UUID) error {
161+
func (f *FakeCoordinator) ServeClient(conn net.Conn, id uuid.UUID, agent uuid.UUID) error {
162162
errCh := make(chan error)
163-
f.serveClientCalls <- &fakeServeClient{
164-
conn: conn,
165-
id: id,
166-
agent: agent,
167-
errCh: errCh,
163+
f.ServeClientCalls <- &FakeServeClient{
164+
Conn: conn,
165+
ID: id,
166+
Agent: agent,
167+
ErrCh: errCh,
168168
}
169169
return <-errCh
170170
}
171171

172-
func (*fakeCoordinator) ServeAgent(net.Conn, uuid.UUID, string) error {
172+
func (*FakeCoordinator) ServeAgent(net.Conn, uuid.UUID, string) error {
173173
panic("unimplemented")
174174
}
175175

176-
func (*fakeCoordinator) Close() error {
176+
func (*FakeCoordinator) Close() error {
177177
panic("unimplemented")
178178
}
179179

180-
func (*fakeCoordinator) ServeMultiAgent(uuid.UUID) tailnet.MultiAgentConn {
180+
func (*FakeCoordinator) ServeMultiAgent(uuid.UUID) tailnet.MultiAgentConn {
181181
panic("unimplemented")
182182
}
183183

184-
func (f *fakeCoordinator) Coordinate(ctx context.Context, id uuid.UUID, name string, a tailnet.TunnelAuth) (chan<- *proto.CoordinateRequest, <-chan *proto.CoordinateResponse) {
184+
func (f *FakeCoordinator) Coordinate(ctx context.Context, id uuid.UUID, name string, a tailnet.TunnelAuth) (chan<- *proto.CoordinateRequest, <-chan *proto.CoordinateResponse) {
185185
reqs := make(chan *proto.CoordinateRequest, 100)
186186
resps := make(chan *proto.CoordinateResponse, 100)
187-
f.coordinateCalls <- &fakeCoordinate{
188-
ctx: ctx,
189-
id: id,
190-
name: name,
191-
auth: a,
192-
reqs: reqs,
193-
resps: resps,
187+
f.CoordinateCalls <- &FakeCoordinate{
188+
Ctx: ctx,
189+
ID: id,
190+
Name: name,
191+
Auth: a,
192+
Reqs: reqs,
193+
Resps: resps,
194194
}
195195
return reqs, resps
196196
}
197197

198-
func newFakeCoordinator() *fakeCoordinator {
199-
return &fakeCoordinator{
200-
coordinateCalls: make(chan *fakeCoordinate, 100),
201-
serveClientCalls: make(chan *fakeServeClient, 100),
198+
func NewFakeCoordinator() *FakeCoordinator {
199+
return &FakeCoordinator{
200+
CoordinateCalls: make(chan *FakeCoordinate, 100),
201+
ServeClientCalls: make(chan *FakeServeClient, 100),
202202
}
203203
}
204204

205-
type fakeCoordinate struct {
206-
ctx context.Context
207-
id uuid.UUID
208-
name string
209-
auth tailnet.TunnelAuth
210-
reqs chan *proto.CoordinateRequest
211-
resps chan *proto.CoordinateResponse
205+
type FakeCoordinate struct {
206+
Ctx context.Context
207+
ID uuid.UUID
208+
Name string
209+
Auth tailnet.TunnelAuth
210+
Reqs chan *proto.CoordinateRequest
211+
Resps chan *proto.CoordinateResponse
212212
}
213213

214-
type fakeServeClient struct {
215-
conn net.Conn
216-
id uuid.UUID
217-
agent uuid.UUID
218-
errCh chan error
214+
type FakeServeClient struct {
215+
Conn net.Conn
216+
ID uuid.UUID
217+
Agent uuid.UUID
218+
ErrCh chan error
219219
}

0 commit comments

Comments
 (0)