MCPcopy Index your code
hub / github.com/coder/coder / TestTunnelSrcCoordController_Mainline

Function TestTunnelSrcCoordController_Mainline

tailnet/controllers_test.go:68–123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

66}
67
68func TestTunnelSrcCoordController_Mainline(t *testing.T) {
69 t.Parallel()
70 ctx := testutil.Context(t, testutil.WaitShort)
71 logger := testutil.Logger(t)
72 clientID := uuid.UUID{1}
73 agentID := uuid.UUID{2}
74 mCoord := tailnettest.NewMockCoordinator(gomock.NewController(t))
75 fConn := &fakeCoordinatee{}
76
77 reqs := make(chan *proto.CoordinateRequest, 100)
78 resps := make(chan *proto.CoordinateResponse, 100)
79 mCoord.EXPECT().Coordinate(gomock.Any(), clientID, gomock.Any(), tailnet.ClientCoordinateeAuth{agentID}).
80 Times(1).Return(reqs, resps)
81
82 var coord tailnet.Coordinator = mCoord
83 coordPtr := atomic.Pointer[tailnet.Coordinator]{}
84 coordPtr.Store(&coord)
85 svc, err := tailnet.NewClientService(tailnet.ClientServiceOptions{
86 Logger: logger.Named("svc"),
87 CoordPtr: &coordPtr,
88 DERPMapUpdateFrequency: time.Hour,
89 DERPMapFn: func() *tailcfg.DERPMap { panic("not implemented") },
90 NetworkTelemetryHandler: func(batch []*proto.TelemetryEvent) { panic("not implemented") },
91 ResumeTokenProvider: tailnet.NewInsecureTestResumeTokenProvider(),
92 })
93 require.NoError(t, err)
94 sC, cC := net.Pipe()
95
96 serveErr := make(chan error, 1)
97 go func() {
98 err := svc.ServeClient(ctx, proto.CurrentVersion.String(), sC, tailnet.StreamID{
99 Name: "client",
100 ID: clientID,
101 Auth: tailnet.ClientCoordinateeAuth{
102 AgentID: agentID,
103 },
104 })
105 serveErr <- err
106 }()
107
108 client, err := tailnet.NewDRPCClient(cC, logger)
109 require.NoError(t, err)
110 protocol, err := client.Coordinate(ctx)
111 require.NoError(t, err)
112
113 ctrl := tailnet.NewTunnelSrcCoordController(logger.Named("coordination"), fConn)
114 ctrl.AddDestination(agentID)
115 uut := ctrl.New(protocol)
116 defer uut.Close(ctx)
117
118 coordinationTest(ctx, t, uut, fConn, reqs, resps, agentID)
119
120 // Recv loop should be terminated by the server hanging up after Disconnect
121 err = testutil.TryReceive(ctx, t, uut.Wait())
122 require.ErrorIs(t, err, io.EOF)
123}
124
125func TestTunnelSrcCoordController_AddDestination(t *testing.T) {

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
ServeClientMethod · 0.95
AddDestinationMethod · 0.95
NewMethod · 0.95
ContextFunction · 0.92
LoggerFunction · 0.92
NewMockCoordinatorFunction · 0.92
NewClientServiceFunction · 0.92
NewDRPCClientFunction · 0.92
TryReceiveFunction · 0.92

Tested by

no test coverage detected