(t *testing.T)
| 310 | } |
| 311 | |
| 312 | func TestTunnelSrcCoordController_Sync(t *testing.T) { |
| 313 | t.Parallel() |
| 314 | ctx := testutil.Context(t, testutil.WaitShort) |
| 315 | logger := testutil.Logger(t) |
| 316 | |
| 317 | fConn := &fakeCoordinatee{} |
| 318 | uut := tailnet.NewTunnelSrcCoordController(logger, fConn) |
| 319 | dest1 := uuid.UUID{1} |
| 320 | dest2 := uuid.UUID{2} |
| 321 | dest3 := uuid.UUID{3} |
| 322 | |
| 323 | // GIVEN: dest1 & dest2 already added |
| 324 | uut.AddDestination(dest1) |
| 325 | uut.AddDestination(dest2) |
| 326 | |
| 327 | // GIVEN: client already connected |
| 328 | client1 := newFakeCoordinatorClient(ctx, t) |
| 329 | cws := make(chan tailnet.CloserWaiter) |
| 330 | go func() { |
| 331 | cws <- uut.New(client1) |
| 332 | }() |
| 333 | for range 2 { |
| 334 | call := testutil.TryReceive(ctx, t, client1.reqs) |
| 335 | testutil.RequireSend(ctx, t, call.err, nil) |
| 336 | } |
| 337 | cw1 := testutil.TryReceive(ctx, t, cws) |
| 338 | |
| 339 | // WHEN: we sync dest2 & dest3 |
| 340 | syncDone := make(chan struct{}) |
| 341 | go func() { |
| 342 | defer close(syncDone) |
| 343 | uut.SyncDestinations([]uuid.UUID{dest2, dest3}) |
| 344 | }() |
| 345 | |
| 346 | // THEN: we get an add for dest3 and remove for dest1 |
| 347 | call := testutil.TryReceive(ctx, t, client1.reqs) |
| 348 | require.Equal(t, dest3[:], call.req.GetAddTunnel().GetId()) |
| 349 | testutil.RequireSend(ctx, t, call.err, nil) |
| 350 | call = testutil.TryReceive(ctx, t, client1.reqs) |
| 351 | require.Equal(t, dest1[:], call.req.GetRemoveTunnel().GetId()) |
| 352 | testutil.RequireSend(ctx, t, call.err, nil) |
| 353 | |
| 354 | testutil.TryReceive(ctx, t, syncDone) |
| 355 | // dest3 should be added to coordinatee |
| 356 | require.Contains(t, fConn.tunnelDestinations, dest3) |
| 357 | |
| 358 | // shut down |
| 359 | respCall := testutil.TryReceive(ctx, t, client1.resps) |
| 360 | testutil.RequireSend(ctx, t, respCall.err, io.EOF) |
| 361 | closeCall := testutil.TryReceive(ctx, t, client1.close) |
| 362 | testutil.RequireSend(ctx, t, closeCall, nil) |
| 363 | err := testutil.TryReceive(ctx, t, cw1.Wait()) |
| 364 | require.ErrorIs(t, err, io.EOF) |
| 365 | } |
| 366 | |
| 367 | func TestTunnelSrcCoordController_AddDestination_Error(t *testing.T) { |
| 368 | t.Parallel() |
nothing calls this directly
no test coverage detected