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

Function TestHTTP

pkg/errors/http_test.go:28–50  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestHTTP(t *testing.T) {
29 t.Parallel()
30 a := assertions.New(t)
31
32 errDef := errors.DefineInvalidArgument("test_http_conversion_err_def", "HTTP Conversion Error", "foo")
33 a.So(errors.FromGRPCStatus(errDef.GRPCStatus()).Definition, should.EqualErrorOrDefinition, errDef)
34
35 errHello := errDef.WithAttributes("foo", "bar", "baz", "qux")
36 errHelloExpected := errDef.WithAttributes("foo", "bar")
37
38 handler := func(w http.ResponseWriter, _ *http.Request) {
39 err := errors.ToHTTP(errHello, w)
40 a.So(err, should.BeNil)
41 }
42
43 req := httptest.NewRequest("GET", "http://example.com/err", nil)
44 w := httptest.NewRecorder()
45 handler(w, req)
46
47 resp := w.Result()
48 a.So(w.Result().StatusCode, should.Equal, http.StatusBadRequest)
49 a.So(errors.FromHTTP(resp), should.EqualErrorOrDefinition, errHelloExpected)
50}

Callers

nothing calls this directly

Calls 9

DefineInvalidArgumentFunction · 0.92
FromGRPCStatusFunction · 0.92
ToHTTPFunction · 0.92
FromHTTPFunction · 0.92
handlerFunction · 0.85
NewMethod · 0.65
ResultMethod · 0.65
GRPCStatusMethod · 0.45
WithAttributesMethod · 0.45

Tested by

no test coverage detected