MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestErrorHandler

Function TestErrorHandler

pkg/webhandlers/error_test.go:63–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestErrorHandler(t *testing.T) {
64 ctx, getError := NewContextWithErrorValue(test.Context())
65
66 err := errors.New("some_error")
67
68 a := assertions.New(t)
69 r := httptest.NewRequest(http.MethodGet, "/", nil)
70 r = r.WithContext(ctx)
71 rec := httptest.NewRecorder()
72
73 Error(rec, r, err)
74
75 res := rec.Result()
76 a.So(res.StatusCode, should.Equal, http.StatusInternalServerError)
77
78 body, _ := io.ReadAll(res.Body)
79 a.So(string(body), should.ContainSubstring, "some_error")
80
81 a.So(getError(), should.EqualErrorOrDefinition, err)
82}

Callers

nothing calls this directly

Calls 6

ContextFunction · 0.92
NewFunction · 0.92
NewContextWithErrorValueFunction · 0.85
ErrorFunction · 0.70
NewMethod · 0.65
ResultMethod · 0.65

Tested by

no test coverage detected