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

Function TestController_WorkspaceUpdates

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

Source from the content-addressed store, hash-verified

1216}
1217
1218func TestController_WorkspaceUpdates(t *testing.T) {
1219 t.Parallel()
1220 theError := xerrors.New("a bad thing happened")
1221 testCtx := testutil.Context(t, testutil.WaitShort)
1222 ctx, cancel := context.WithCancel(testCtx)
1223 logger := slogtest.Make(t, &slogtest.Options{
1224 IgnoredErrorIs: append(slogtest.DefaultIgnoredErrorIs, theError),
1225 }).Leveled(slog.LevelDebug)
1226
1227 fClient := newFakeWorkspaceUpdateClient(testCtx, t)
1228 dialer := &fakeWorkspaceUpdatesDialer{
1229 client: fClient,
1230 }
1231
1232 uut := tailnet.NewController(logger.Named("ctrl"), dialer)
1233 fCtrl := newFakeUpdatesController(ctx, t)
1234 uut.WorkspaceUpdatesCtrl = fCtrl
1235 uut.Run(ctx)
1236
1237 // it should dial and pass the client to the controller
1238 call := testutil.TryReceive(testCtx, t, fCtrl.calls)
1239 require.Equal(t, fClient, call.client)
1240 fCW := newFakeCloserWaiter()
1241 testutil.RequireSend[tailnet.CloserWaiter](testCtx, t, call.resp, fCW)
1242
1243 // if the CloserWaiter exits...
1244 testutil.RequireSend(testCtx, t, fCW.errCh, theError)
1245
1246 // it should close, redial and reconnect
1247 cCall := testutil.TryReceive(testCtx, t, fClient.close)
1248 testutil.RequireSend(testCtx, t, cCall, nil)
1249
1250 call = testutil.TryReceive(testCtx, t, fCtrl.calls)
1251 require.Equal(t, fClient, call.client)
1252 fCW = newFakeCloserWaiter()
1253 testutil.RequireSend[tailnet.CloserWaiter](testCtx, t, call.resp, fCW)
1254
1255 // canceling the context should close the client
1256 cancel()
1257 cCall = testutil.TryReceive(testCtx, t, fClient.close)
1258 testutil.RequireSend(testCtx, t, cCall, nil)
1259}
1260
1261type fakeTailnetConn struct {
1262 peersLostCh chan struct{}

Callers

nothing calls this directly

Calls 11

RunMethod · 0.95
ContextFunction · 0.92
NewControllerFunction · 0.92
TryReceiveFunction · 0.92
RequireSendFunction · 0.92
newFakeUpdatesControllerFunction · 0.85
newFakeCloserWaiterFunction · 0.85
NamedMethod · 0.80
NewMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected