dialWSPath connects to a specific WS path on the test server, authenticating with the Authorization: Bearer header (the credential is never in the URL).
(t *testing.T, srv *httptest.Server, path, token string)
| 74 | // dialWSPath connects to a specific WS path on the test server, authenticating |
| 75 | // with the Authorization: Bearer header (the credential is never in the URL). |
| 76 | func dialWSPath(t *testing.T, srv *httptest.Server, path, token string) (*websocket.Conn, *http.Response) { |
| 77 | t.Helper() |
| 78 | url := fmt.Sprintf("ws%s%s", strings.TrimPrefix(srv.URL, "http"), path) |
| 79 | ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) |
| 80 | defer cancel() |
| 81 | opts := &websocket.DialOptions{HTTPHeader: http.Header{}} |
| 82 | if token != "" { |
| 83 | opts.HTTPHeader.Set("Authorization", "Bearer "+token) |
| 84 | } |
| 85 | conn, resp, err := websocket.Dial(ctx, url, opts) |
| 86 | if err != nil { |
| 87 | // Return nil conn for error-path tests |
| 88 | return nil, resp |
| 89 | } |
| 90 | return conn, resp |
| 91 | } |
| 92 | |
| 93 | // dialWS connects to the versioned WS endpoint. |
| 94 | func dialWS(t *testing.T, srv *httptest.Server, email, token string) (*websocket.Conn, *http.Response) { |