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

Function Test_CookieJarHostCapacityPrefersExpiredEntries

client/cookiejar_test.go:232–259  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

230}
231
232func Test_CookieJarHostCapacityPrefersExpiredEntries(t *testing.T) {
233 t.Parallel()
234
235 cj := &CookieJar{hostCookies: make(map[string][]storedCookie, maxCookieJarHosts)}
236 now := time.Now()
237
238 expired := fasthttp.AcquireCookie()
239 expired.SetKey("expired")
240 expired.SetValue("v")
241 expired.SetExpire(now.Add(-time.Minute))
242 cj.hostCookies["expired.example.com"] = []storedCookie{{cookie: expired, isHostOnly: true}}
243
244 for i := 1; i < maxCookieJarHosts; i++ {
245 host := fmt.Sprintf("host-%04d.example.com", i)
246 cookie := fasthttp.AcquireCookie()
247 cookie.SetKey("k")
248 cookie.SetValue("v")
249 cj.hostCookies[host] = []storedCookie{{cookie: cookie, isHostOnly: true}}
250 }
251
252 cj.ensureHostCapacityLocked("new.example.com", now)
253
254 _, ok := cj.hostCookies["expired.example.com"]
255 require.False(t, ok)
256 require.Len(t, cj.hostCookies, maxCookieJarHosts-1)
257 _, ok = cj.hostCookies["host-0001.example.com"]
258 require.True(t, ok)
259}
260
261func Test_CookieJarGetFromResponse(t *testing.T) {
262 t.Parallel()

Callers

nothing calls this directly

Calls 4

AddMethod · 0.65
LenMethod · 0.65
NowMethod · 0.45

Tested by

no test coverage detected