(t *testing.T)
| 304 | } |
| 305 | |
| 306 | func Test_Client_HostClient_Behavior(t *testing.T) { |
| 307 | t.Parallel() |
| 308 | |
| 309 | t.Run("do and redirects", func(t *testing.T) { |
| 310 | t.Parallel() |
| 311 | |
| 312 | app, addr := startTestServerWithPort(t, func(app *fiber.App) { |
| 313 | app.Get("/ok", func(c fiber.Ctx) error { |
| 314 | return c.SendString("ok") |
| 315 | }) |
| 316 | app.Get("/redirect", func(c fiber.Ctx) error { |
| 317 | return c.Redirect().Status(fiber.StatusFound).To("/ok") |
| 318 | }) |
| 319 | }) |
| 320 | t.Cleanup(func() { |
| 321 | require.NoError(t, app.Shutdown()) |
| 322 | }) |
| 323 | |
| 324 | client := NewWithHostClient(&fasthttp.HostClient{Addr: addr}) |
| 325 | |
| 326 | resp, err := client.Get("http://" + addr + "/ok") |
| 327 | require.NoError(t, err) |
| 328 | require.Equal(t, fiber.StatusOK, resp.StatusCode()) |
| 329 | require.Equal(t, "ok", resp.String()) |
| 330 | |
| 331 | resp, err = client.Get("http://"+addr+"/redirect", Config{MaxRedirects: 1}) |
| 332 | require.NoError(t, err) |
| 333 | require.Equal(t, fiber.StatusOK, resp.StatusCode()) |
| 334 | require.Equal(t, "ok", resp.String()) |
| 335 | }) |
| 336 | |
| 337 | t.Run("retries respect dial overrides", func(t *testing.T) { |
| 338 | t.Parallel() |
| 339 | |
| 340 | app, addr := startTestServerWithPort(t, func(app *fiber.App) { |
| 341 | app.Get("/", func(c fiber.Ctx) error { |
| 342 | return c.SendString("retry") |
| 343 | }) |
| 344 | }) |
| 345 | t.Cleanup(func() { |
| 346 | require.NoError(t, app.Shutdown()) |
| 347 | }) |
| 348 | |
| 349 | client := NewWithHostClient(&fasthttp.HostClient{Addr: addr}) |
| 350 | client.SetRetryConfig(&RetryConfig{ |
| 351 | InitialInterval: time.Millisecond, |
| 352 | MaxRetryCount: 2, |
| 353 | }) |
| 354 | |
| 355 | var attempts atomic.Int32 |
| 356 | client.SetDial(func(address string) (net.Conn, error) { |
| 357 | if attempts.Add(1) == 1 { |
| 358 | return nil, errors.New("dial failure") |
| 359 | } |
| 360 | return fasthttp.Dial(address) |
| 361 | }) |
| 362 | |
| 363 | resp, err := client.Get("http://" + addr) |
nothing calls this directly
no test coverage detected