(t *testing.T, logger slog.Logger, serverURL *url.URL, me, peer Client, options *tailnet.Options)
| 499 | } |
| 500 | |
| 501 | func startClientOptions(t *testing.T, logger slog.Logger, serverURL *url.URL, me, peer Client, options *tailnet.Options) *tailnet.Conn { |
| 502 | u, err := serverURL.Parse(fmt.Sprintf("/api/v2/workspaceagents/%s/coordinate", me.ID.String())) |
| 503 | require.NoError(t, err) |
| 504 | //nolint:bodyclose |
| 505 | ws, _, err := websocket.Dial(context.Background(), u.String(), nil) |
| 506 | require.NoError(t, err) |
| 507 | t.Cleanup(func() { |
| 508 | _ = ws.Close(websocket.StatusNormalClosure, "closing websocket") |
| 509 | }) |
| 510 | |
| 511 | client, err := tailnet.NewDRPCClient( |
| 512 | websocket.NetConn(context.Background(), ws, websocket.MessageBinary), |
| 513 | logger, |
| 514 | ) |
| 515 | require.NoError(t, err) |
| 516 | |
| 517 | coord, err := client.Coordinate(context.Background()) |
| 518 | require.NoError(t, err) |
| 519 | |
| 520 | conn, err := tailnet.NewConn(options) |
| 521 | require.NoError(t, err) |
| 522 | t.Cleanup(func() { |
| 523 | _ = conn.Close() |
| 524 | }) |
| 525 | |
| 526 | var coordination tailnet.CloserWaiter |
| 527 | if me.TunnelSrc { |
| 528 | ctrl := tailnet.NewTunnelSrcCoordController(logger, conn) |
| 529 | ctrl.AddDestination(peer.ID) |
| 530 | coordination = ctrl.New(coord) |
| 531 | } else { |
| 532 | // use the "Agent" controller so that we act as a tunnel destination and send "ReadyForHandshake" acks. |
| 533 | ctrl := tailnet.NewAgentCoordinationController(logger, conn) |
| 534 | coordination = ctrl.New(coord) |
| 535 | } |
| 536 | t.Cleanup(func() { |
| 537 | cctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) |
| 538 | defer cancel() |
| 539 | _ = coordination.Close(cctx) |
| 540 | }) |
| 541 | |
| 542 | return conn |
| 543 | } |
| 544 | |
| 545 | func basicDERPMap(serverURLStr string) (*tailcfg.DERPMap, error) { |
| 546 | serverURL, err := url.Parse(serverURLStr) |
no test coverage detected