(t *testing.T, agentNum int, opts ...tailnettest.DERPAndStunOption)
| 430 | } |
| 431 | |
| 432 | func setupServerTailnetAgent(t *testing.T, agentNum int, opts ...tailnettest.DERPAndStunOption) ([]agentWithID, *coderd.ServerTailnet) { |
| 433 | logger := testutil.Logger(t) |
| 434 | derpMap, derpServer := tailnettest.RunDERPAndSTUN(t, opts...) |
| 435 | |
| 436 | coord := tailnet.NewCoordinator(logger) |
| 437 | t.Cleanup(func() { |
| 438 | _ = coord.Close() |
| 439 | }) |
| 440 | coordPtr := atomic.Pointer[tailnet.Coordinator]{} |
| 441 | coordPtr.Store(&coord) |
| 442 | |
| 443 | agents := []agentWithID{} |
| 444 | |
| 445 | for i := 0; i < agentNum; i++ { |
| 446 | manifest := agentsdk.Manifest{ |
| 447 | AgentID: uuid.New(), |
| 448 | DERPMap: derpMap, |
| 449 | } |
| 450 | |
| 451 | c := agenttest.NewClient(t, logger, manifest.AgentID, manifest, make(chan *proto.Stats, 50), coord) |
| 452 | t.Cleanup(c.Close) |
| 453 | |
| 454 | options := agent.Options{ |
| 455 | Client: c, |
| 456 | Filesystem: afero.NewMemMapFs(), |
| 457 | Logger: logger.Named("agent"), |
| 458 | } |
| 459 | |
| 460 | ag := agent.New(options) |
| 461 | t.Cleanup(func() { |
| 462 | _ = ag.Close() |
| 463 | }) |
| 464 | |
| 465 | // Wait for the agent to connect. |
| 466 | require.Eventually(t, func() bool { |
| 467 | return coord.Node(manifest.AgentID) != nil |
| 468 | }, testutil.WaitShort, testutil.IntervalFast) |
| 469 | |
| 470 | agents = append(agents, agentWithID{id: manifest.AgentID, Agent: ag}) |
| 471 | } |
| 472 | |
| 473 | dialer := &coderd.InmemTailnetDialer{ |
| 474 | CoordPtr: &coordPtr, |
| 475 | DERPFn: func() *tailcfg.DERPMap { return derpMap }, |
| 476 | Logger: logger, |
| 477 | ClientID: uuid.UUID{5}, |
| 478 | } |
| 479 | serverTailnet, err := coderd.NewServerTailnet( |
| 480 | context.Background(), |
| 481 | logger, |
| 482 | derpServer, |
| 483 | dialer, |
| 484 | false, |
| 485 | !derpMap.HasSTUN(), |
| 486 | trace.NewNoopTracerProvider(), |
| 487 | ) |
| 488 | require.NoError(t, err) |
| 489 |
no test coverage detected