(t *testing.T)
| 26 | ) |
| 27 | |
| 28 | func 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 | } |
nothing calls this directly
no test coverage detected