MCPcopy
hub / github.com/gofiber/fiber / Test_Cache_MaxBytesSizes

Function Test_Cache_MaxBytesSizes

middleware/cache/cache_test.go:1943–1975  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1941}
1942
1943func 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
1977func Test_Cache_UncacheableStatusCodes(t *testing.T) {
1978 t.Parallel()

Callers

nothing calls this directly

Calls 9

URIMethod · 0.80
TestMethod · 0.80
NewFunction · 0.70
NewMethod · 0.65
UseMethod · 0.65
GetMethod · 0.65
RequestCtxMethod · 0.65
SendMethod · 0.65

Tested by

no test coverage detected