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

Function TestInternalServerError

coderd/httpapi/httpapi_test.go:27–59  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestInternalServerError(t *testing.T) {
28 t.Parallel()
29
30 t.Run("NoError", func(t *testing.T) {
31 t.Parallel()
32 w := httptest.NewRecorder()
33 httpapi.InternalServerError(w, nil)
34
35 var resp codersdk.Response
36 err := json.NewDecoder(w.Body).Decode(&resp)
37 require.NoError(t, err)
38 require.Equal(t, http.StatusInternalServerError, w.Code)
39 require.NotEmpty(t, resp.Message)
40 require.Empty(t, resp.Detail)
41 })
42
43 t.Run("WithError", func(t *testing.T) {
44 t.Parallel()
45 var (
46 w = httptest.NewRecorder()
47 httpErr = xerrors.New("error!")
48 )
49
50 httpapi.InternalServerError(w, httpErr)
51
52 var resp codersdk.Response
53 err := json.NewDecoder(w.Body).Decode(&resp)
54 require.NoError(t, err)
55 require.Equal(t, http.StatusInternalServerError, w.Code)
56 require.NotEmpty(t, resp.Message)
57 require.Equal(t, httpErr.Error(), resp.Detail)
58 })
59}
60
61func TestWrite(t *testing.T) {
62 t.Parallel()

Callers

nothing calls this directly

Calls 7

InternalServerErrorFunction · 0.92
NotEmptyMethod · 0.80
RunMethod · 0.65
NewMethod · 0.65
EqualMethod · 0.45
EmptyMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected