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

Function TestBuildErrorResponseDelegation

coderd/wsbuilder/builderror_test.go:15–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestBuildErrorResponseDelegation(t *testing.T) {
16 t.Parallel()
17
18 t.Run("plain_error", func(t *testing.T) {
19 t.Parallel()
20
21 be := wsbuilder.BuildError{
22 Status: http.StatusBadRequest,
23 Message: "bad",
24 Wrapped: xerrors.New("oops"),
25 }
26
27 status, resp := be.Response()
28 require.Equal(t, http.StatusBadRequest, status)
29 require.Equal(t, "bad", resp.Message)
30 require.Contains(t, resp.Detail, "oops")
31 require.Empty(t, resp.Validations)
32 })
33
34 t.Run("responder_error", func(t *testing.T) {
35 t.Parallel()
36
37 inner := &dynamicparameters.DiagnosticError{
38 Message: "resolve parameters",
39 KeyedDiagnostics: map[string]hcl.Diagnostics{
40 "param1": {
41 {
42 Severity: hcl.DiagError,
43 Summary: "required parameter",
44 },
45 },
46 },
47 }
48
49 be := wsbuilder.BuildError{
50 Status: http.StatusBadRequest,
51 Message: "build error wrapper",
52 Wrapped: inner,
53 }
54
55 status, resp := be.Response()
56
57 // Should delegate to the inner DiagnosticError's response.
58 innerStatus, innerResp := inner.Response()
59 require.Equal(t, innerStatus, status)
60 require.Equal(t, innerResp.Message, resp.Message)
61 require.Len(t, resp.Validations, 1)
62 require.Equal(t, "param1", resp.Validations[0].Field)
63 })
64}

Callers

nothing calls this directly

Calls 8

ResponseMethod · 0.95
ResponseMethod · 0.95
RunMethod · 0.65
NewMethod · 0.65
EqualMethod · 0.45
ContainsMethod · 0.45
EmptyMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected