(ctx context.Context, url string)
| 68 | } |
| 69 | |
| 70 | func (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 | |
| 96 | func TestWatcher_Agents(t *testing.T) { |
| 97 | t.Parallel() |
nothing calls this directly
no test coverage detected