(t *testing.T)
| 1941 | } |
| 1942 | |
| 1943 | func Test_Cache_MaxBytesSizes(t *testing.T) { |
| 1944 | t.Parallel() |
| 1945 | app := fiber.New() |
| 1946 | |
| 1947 | app.Use(New(Config{ |
| 1948 | MaxBytes: 7, |
| 1949 | ExpirationGenerator: stableAscendingExpiration(), |
| 1950 | })) |
| 1951 | |
| 1952 | app.Get("/*", func(c fiber.Ctx) error { |
| 1953 | path := c.RequestCtx().URI().LastPathSegment() |
| 1954 | size, err := strconv.Atoi(string(path)) |
| 1955 | require.NoError(t, err) |
| 1956 | return c.Send(make([]byte, size)) |
| 1957 | }) |
| 1958 | |
| 1959 | cases := [][]string{ |
| 1960 | {"/1", cacheMiss}, |
| 1961 | {"/2", cacheMiss}, |
| 1962 | {"/3", cacheMiss}, |
| 1963 | {"/4", cacheMiss}, // 1+2+3+4 > 7 => 1,2 are evicted now |
| 1964 | {"/3", cacheHit}, |
| 1965 | {"/1", cacheMiss}, |
| 1966 | {"/2", cacheMiss}, |
| 1967 | {"/8", cacheUnreachable}, // too big to cache -> unreachable |
| 1968 | } |
| 1969 | |
| 1970 | for idx, tcase := range cases { |
| 1971 | rsp, err := app.Test(httptest.NewRequest(fiber.MethodGet, tcase[0], http.NoBody)) |
| 1972 | require.NoError(t, err) |
| 1973 | require.Equal(t, tcase[1], rsp.Header.Get("X-Cache"), "Case %v", idx) |
| 1974 | } |
| 1975 | } |
| 1976 | |
| 1977 | func Test_Cache_UncacheableStatusCodes(t *testing.T) { |
| 1978 | t.Parallel() |
nothing calls this directly
no test coverage detected