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

Method Dial

coderd/workspaceconnwatcher/watcher_test.go:70–94  ·  view source on GitHub ↗
(ctx context.Context, url string)

Source from the content-addressed store, hash-verified

68}
69
70func (h *harness) Dial(ctx context.Context, url string) (*wsjson.Decoder[workspacesdk.ConnectionWatchEvent], error) {
71 rt := testutil.InMemWebsocketRoundTripper{
72 Handler: http.HandlerFunc(h.watcher.WorkspaceAgentConnectionWatch),
73 CtxMutator: func(ctx context.Context) context.Context {
74 ctx = httpmw.WithWorkspaceParam(ctx, h.workspace)
75 ctx = dbauthz.As(ctx, coderdtest.MemberSubject(userID, orgID))
76 return ctx
77 },
78 Logger: h.logger.Named("roundtripper"),
79 }
80 // nolint: bodyclose
81 clientSock, resp, err := websocket.Dial(ctx, url, &websocket.DialOptions{
82 HTTPClient: &http.Client{Transport: rt},
83 })
84 if err != nil {
85 if resp.StatusCode != http.StatusSwitchingProtocols {
86 return nil, codersdk.ReadBodyAsError(resp)
87 }
88 return nil, err
89 }
90
91 dec := wsjson.NewDecoder[workspacesdk.ConnectionWatchEvent](
92 clientSock, websocket.MessageText, h.logger.Named("decoder"))
93 return dec, nil
94}
95
96func TestWatcher_Agents(t *testing.T) {
97 t.Parallel()

Callers

nothing calls this directly

Calls 7

WithWorkspaceParamFunction · 0.92
AsFunction · 0.92
MemberSubjectFunction · 0.92
ReadBodyAsErrorFunction · 0.92
NewDecoderFunction · 0.92
NamedMethod · 0.80
DialMethod · 0.65

Tested by

no test coverage detected