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

Function TestCoordinator

tailnet/coordinator_test.go:20–249  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestCoordinator(t *testing.T) {
21 t.Parallel()
22 t.Run("ClientWithoutAgent", func(t *testing.T) {
23 t.Parallel()
24 logger := testutil.Logger(t)
25 ctx := testutil.Context(t, testutil.WaitShort)
26 coordinator := tailnet.NewCoordinator(logger)
27 defer func() {
28 err := coordinator.Close()
29 require.NoError(t, err)
30 }()
31
32 client := test.NewClient(ctx, t, coordinator, "client", uuid.New())
33 defer client.Close(ctx)
34 client.UpdateNode(&proto.Node{
35 Addresses: []string{tailnet.TailscaleServicePrefix.RandomPrefix().String()},
36 PreferredDerp: 10,
37 })
38 require.Eventually(t, func() bool {
39 return coordinator.Node(client.ID) != nil
40 }, testutil.WaitShort, testutil.IntervalFast)
41 })
42
43 t.Run("ClientWithoutAgent_InvalidIPBits", func(t *testing.T) {
44 t.Parallel()
45 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
46 ctx := testutil.Context(t, testutil.WaitShort)
47 coordinator := tailnet.NewCoordinator(logger)
48 defer func() {
49 err := coordinator.Close()
50 require.NoError(t, err)
51 }()
52
53 client := test.NewClient(ctx, t, coordinator, "client", uuid.New())
54 defer client.Close(ctx)
55
56 client.UpdateNode(&proto.Node{
57 Addresses: []string{
58 netip.PrefixFrom(tailnet.TailscaleServicePrefix.RandomAddr(), 64).String(),
59 },
60 PreferredDerp: 10,
61 })
62 client.AssertEventuallyResponsesClosed(
63 tailnet.AuthorizationError{Wrapped: tailnet.InvalidAddressBitsError{Bits: 64}}.Error())
64 })
65
66 t.Run("AgentWithoutClients", func(t *testing.T) {
67 t.Parallel()
68 logger := testutil.Logger(t)
69 ctx := testutil.Context(t, testutil.WaitShort)
70 coordinator := tailnet.NewCoordinator(logger)
71 defer func() {
72 err := coordinator.Close()
73 require.NoError(t, err)
74 }()
75
76 agent := test.NewAgent(ctx, t, coordinator, "agent")
77 defer agent.Close(ctx)

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
UpdateNodeMethod · 0.95
CloseMethod · 0.95
UpdateDERPMethod · 0.95
AddTunnelMethod · 0.95
LoggerFunction · 0.92
ContextFunction · 0.92
NewCoordinatorFunction · 0.92
NewClientFunction · 0.92
NewAgentFunction · 0.92

Tested by

no test coverage detected