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

Function TestWorkspaceDialerFailure

codersdk/workspacesdk/workspacesdk_test.go:54–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

52}
53
54func 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
81func TestClient_IsCoderConnectRunning(t *testing.T) {
82 t.Parallel()

Callers

nothing calls this directly

Calls 7

DialMethod · 0.95
ContextFunction · 0.92
LoggerFunction · 0.92
WriteFunction · 0.92
NewWebsocketDialerFunction · 0.92
CleanupMethod · 0.65
ParseMethod · 0.65

Tested by

no test coverage detected