| 52 | } |
| 53 | |
| 54 | func TestWorkspaceDialerFailure(t *testing.T) { |
| 55 | t.Parallel() |
| 56 | |
| 57 | // Setup. |
| 58 | ctx := testutil.Context(t, testutil.WaitShort) |
| 59 | logger := testutil.Logger(t) |
| 60 | |
| 61 | // Given: a mock HTTP server which mimicks an unreachable database when calling the coordination endpoint. |
| 62 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 63 | httpapi.Write(ctx, w, http.StatusInternalServerError, codersdk.Response{ |
| 64 | Message: codersdk.DatabaseNotReachable, |
| 65 | Detail: "oops", |
| 66 | }) |
| 67 | })) |
| 68 | t.Cleanup(srv.Close) |
| 69 | |
| 70 | u, err := url.Parse(srv.URL) |
| 71 | require.NoError(t, err) |
| 72 | |
| 73 | // When: calling the coordination endpoint. |
| 74 | dialer := workspacesdk.NewWebsocketDialer(logger, u, &websocket.DialOptions{}) |
| 75 | _, err = dialer.Dial(ctx, nil) |
| 76 | |
| 77 | // Then: an error indicating a database issue is returned, to conditionalize the behavior of the caller. |
| 78 | require.ErrorIs(t, err, codersdk.ErrDatabaseNotReachable) |
| 79 | } |
| 80 | |
| 81 | func TestClient_IsCoderConnectRunning(t *testing.T) { |
| 82 | t.Parallel() |