(t *testing.T)
| 230 | } |
| 231 | |
| 232 | func 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 | |
| 261 | func Test_CookieJarGetFromResponse(t *testing.T) { |
| 262 | t.Parallel() |
nothing calls this directly
no test coverage detected