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

Function TestClient_WorkspaceUpdates

vpn/client_test.go:31–221  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29)
30
31func TestClient_WorkspaceUpdates(t *testing.T) {
32 t.Parallel()
33
34 userID := uuid.UUID{1}
35 wsID := uuid.UUID{2}
36 peerID := uuid.UUID{3}
37 agentID := uuid.UUID{4}
38
39 testCases := []struct {
40 name string
41 agentConnectionInfo workspacesdk.AgentConnectionInfo
42 hostnames []string
43 }{
44 {
45 name: "empty",
46 agentConnectionInfo: workspacesdk.AgentConnectionInfo{
47 DERPMap: &tailcfg.DERPMap{},
48 },
49 hostnames: []string{"wrk.coder.", "agnt.wrk.me.coder.", "agnt.wrk.rootbeer.coder."},
50 },
51 {
52 name: "suffix",
53 agentConnectionInfo: workspacesdk.AgentConnectionInfo{
54 HostnameSuffix: "float",
55 DERPMap: &tailcfg.DERPMap{},
56 },
57 hostnames: []string{"wrk.float.", "agnt.wrk.me.float.", "agnt.wrk.rootbeer.float."},
58 },
59 }
60 for _, tc := range testCases {
61 t.Run(tc.name, func(t *testing.T) {
62 t.Parallel()
63
64 ctx := testutil.Context(t, testutil.WaitShort)
65 logger := testutil.Logger(t)
66
67 fCoord := tailnettest.NewFakeCoordinator()
68 var coord tailnet.Coordinator = fCoord
69 coordPtr := atomic.Pointer[tailnet.Coordinator]{}
70 coordPtr.Store(&coord)
71 ctrl := gomock.NewController(t)
72 mProvider := tailnettest.NewMockWorkspaceUpdatesProvider(ctrl)
73
74 mSub := tailnettest.NewMockSubscription(ctrl)
75 outUpdateCh := make(chan *proto.WorkspaceUpdate, 1)
76 inUpdateCh := make(chan tailnet.WorkspaceUpdate, 1)
77 mProvider.EXPECT().Subscribe(gomock.Any(), userID).Times(1).Return(mSub, nil)
78 mSub.EXPECT().Updates().MinTimes(1).Return(outUpdateCh)
79 mSub.EXPECT().Close().Times(1).Return(nil)
80
81 svc, err := tailnet.NewClientService(tailnet.ClientServiceOptions{
82 Logger: logger,
83 CoordPtr: &coordPtr,
84 DERPMapUpdateFrequency: time.Hour,
85 DERPMapFn: func() *tailcfg.DERPMap { return &tailcfg.DERPMap{} },
86 WorkspaceUpdatesProvider: mProvider,
87 ResumeTokenProvider: tailnet.NewInsecureTestResumeTokenProvider(),
88 })

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
EXPECTMethod · 0.95
CloseMethod · 0.95
ServeConnV2Method · 0.95
CurrentWorkspaceStateMethod · 0.95
ContextFunction · 0.92
LoggerFunction · 0.92
NewFakeCoordinatorFunction · 0.92
NewMockSubscriptionFunction · 0.92
NewClientServiceFunction · 0.92

Tested by

no test coverage detected