| 66 | } |
| 67 | |
| 68 | func TestReadErr(t *testing.T) { |
| 69 | var gotErr error |
| 70 | errFunc := func(ctx context.Context, w http.ResponseWriter, err error) { |
| 71 | gotErr = errors.Root(err) |
| 72 | } |
| 73 | h, _ := Handler(func(int) {}, errFunc) |
| 74 | |
| 75 | resp := httptest.NewRecorder() |
| 76 | body := iotest.OneByteReader(iotest.TimeoutReader(strings.NewReader("123456"))) |
| 77 | req, _ := http.NewRequest("GET", "/", body) |
| 78 | h.ServeHTTP(resp, req) |
| 79 | if got := resp.Body.Len(); got != 0 { |
| 80 | t.Errorf("len(response) = %d want 0", got) |
| 81 | } |
| 82 | wantErr := ErrBadRequest |
| 83 | if gotErr != wantErr { |
| 84 | t.Errorf("err = %v want %v", gotErr, wantErr) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | func TestFuncInputTypeError(t *testing.T) { |
| 89 | cases := []interface{}{ |