(t *testing.T)
| 1684 | } |
| 1685 | |
| 1686 | func Test_Cache_WithHead(t *testing.T) { |
| 1687 | t.Parallel() |
| 1688 | |
| 1689 | app := fiber.New() |
| 1690 | app.Use(New()) |
| 1691 | |
| 1692 | count := 0 |
| 1693 | handler := func(c fiber.Ctx) error { |
| 1694 | count++ |
| 1695 | c.Response().Header.Add("Cache-Time", "1") |
| 1696 | return c.SendString(strconv.Itoa(count)) |
| 1697 | } |
| 1698 | |
| 1699 | app.RouteChain("/").Get(handler).Head(handler) |
| 1700 | |
| 1701 | req := httptest.NewRequest(fiber.MethodHead, "/", http.NoBody) |
| 1702 | resp, err := app.Test(req) |
| 1703 | require.NoError(t, err) |
| 1704 | require.Equal(t, cacheMiss, resp.Header.Get("X-Cache")) |
| 1705 | |
| 1706 | cachedReq := httptest.NewRequest(fiber.MethodHead, "/", http.NoBody) |
| 1707 | cachedResp, err := app.Test(cachedReq) |
| 1708 | require.NoError(t, err) |
| 1709 | require.Equal(t, cacheHit, cachedResp.Header.Get("X-Cache")) |
| 1710 | |
| 1711 | body, err := io.ReadAll(resp.Body) |
| 1712 | require.NoError(t, err) |
| 1713 | cachedBody, err := io.ReadAll(cachedResp.Body) |
| 1714 | require.NoError(t, err) |
| 1715 | |
| 1716 | require.Equal(t, cachedBody, body) |
| 1717 | } |
| 1718 | |
| 1719 | func Test_Cache_WithHeadThenGet(t *testing.T) { |
| 1720 | t.Parallel() |
nothing calls this directly
no test coverage detected