(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func Test_Exec_Func(t *testing.T) { |
| 22 | t.Parallel() |
| 23 | ln := fasthttputil.NewInmemoryListener() |
| 24 | app := fiber.New() |
| 25 | |
| 26 | app.Get("/normal", func(c fiber.Ctx) error { |
| 27 | return c.SendString(c.Hostname()) |
| 28 | }) |
| 29 | |
| 30 | app.Get("/return-error", func(_ fiber.Ctx) error { |
| 31 | return errors.New("the request is error") |
| 32 | }) |
| 33 | |
| 34 | app.Get("/redirect", func(c fiber.Ctx) error { |
| 35 | return c.Redirect().Status(fiber.StatusFound).To("/normal") |
| 36 | }) |
| 37 | |
| 38 | app.Get("/hang-up", func(c fiber.Ctx) error { |
| 39 | time.Sleep(time.Second) |
| 40 | return c.SendString(c.Hostname() + " hang up") |
| 41 | }) |
| 42 | |
| 43 | go func() { |
| 44 | assert.NoError(t, app.Listener(ln, fiber.ListenConfig{DisableStartupMessage: true})) |
| 45 | }() |
| 46 | |
| 47 | time.Sleep(300 * time.Millisecond) |
| 48 | |
| 49 | t.Run("normal request", func(t *testing.T) { |
| 50 | t.Parallel() |
| 51 | core, client, req := newCore(), New(), AcquireRequest() |
| 52 | core.ctx = context.Background() |
| 53 | core.client = client |
| 54 | core.req = req |
| 55 | |
| 56 | client.SetDial(func(_ string) (net.Conn, error) { return ln.Dial() }) |
| 57 | req.RawRequest.SetRequestURI("http://example.com/normal") |
| 58 | |
| 59 | resp, err := core.execFunc() |
| 60 | require.NoError(t, err) |
| 61 | require.Equal(t, 200, resp.RawResponse.StatusCode()) |
| 62 | require.Equal(t, "example.com", string(resp.RawResponse.Body())) |
| 63 | }) |
| 64 | |
| 65 | t.Run("follow redirect with retry config", func(t *testing.T) { |
| 66 | t.Parallel() |
| 67 | core, client, req := newCore(), New(), AcquireRequest() |
| 68 | core.ctx = context.Background() |
| 69 | core.client = client |
| 70 | core.req = req |
| 71 | |
| 72 | client.SetRetryConfig(&RetryConfig{MaxRetryCount: 1}) |
| 73 | client.SetDial(func(_ string) (net.Conn, error) { return ln.Dial() }) |
| 74 | req.SetMaxRedirects(1) |
| 75 | req.RawRequest.Header.SetMethod(fiber.MethodGet) |
| 76 | req.RawRequest.SetRequestURI("http://example.com/redirect") |
| 77 | |
| 78 | resp, err := core.execFunc() |
nothing calls this directly
no test coverage detected