(t *testing.T)
| 1216 | } |
| 1217 | |
| 1218 | func 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 | |
| 1261 | type fakeTailnetConn struct { |
| 1262 | peersLostCh chan struct{} |
nothing calls this directly
no test coverage detected