(t *testing.T)
| 57 | } |
| 58 | |
| 59 | func TestServerErrorEncoder(t *testing.T) { |
| 60 | errTeapot := errors.New("teapot") |
| 61 | code := func(err error) int { |
| 62 | if errors.Is(err, errTeapot) { |
| 63 | return http.StatusTeapot |
| 64 | } |
| 65 | return http.StatusInternalServerError |
| 66 | } |
| 67 | handler := httptransport.NewServer( |
| 68 | func(context.Context, interface{}) (interface{}, error) { return struct{}{}, errTeapot }, |
| 69 | func(context.Context, *http.Request) (interface{}, error) { return struct{}{}, nil }, |
| 70 | func(context.Context, http.ResponseWriter, interface{}) error { return nil }, |
| 71 | httptransport.ServerErrorEncoder(func(_ context.Context, err error, w http.ResponseWriter) { w.WriteHeader(code(err)) }), |
| 72 | ) |
| 73 | server := httptest.NewServer(handler) |
| 74 | defer server.Close() |
| 75 | resp, _ := http.Get(server.URL) |
| 76 | if want, have := http.StatusTeapot, resp.StatusCode; want != have { |
| 77 | t.Errorf("want %d, have %d", want, have) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | func TestServerHappyPath(t *testing.T) { |
| 82 | step, response := testServer(t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…