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

Function Test_Client_CookieJar_Response

client/client_test.go:1535–1642  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1533}
1534
1535func Test_Client_CookieJar_Response(t *testing.T) {
1536 t.Parallel()
1537
1538 t.Run("without expiration", func(t *testing.T) {
1539 t.Parallel()
1540 handler := func(c fiber.Ctx) error {
1541 c.Cookie(&fiber.Cookie{
1542 Name: "k4",
1543 Value: "v4",
1544 })
1545 return c.SendString(
1546 c.Cookies("k1") + c.Cookies("k2") + c.Cookies("k3"),
1547 )
1548 }
1549
1550 jar := AcquireCookieJar()
1551 defer ReleaseCookieJar(jar)
1552
1553 jar.SetKeyValue("example.com", "k1", "v1")
1554 jar.SetKeyValue("example.com", "k2", "v2")
1555 jar.SetKeyValue("example", "k3", "v3")
1556
1557 wrapAgent := func(c *Client) {
1558 c.SetCookieJar(jar)
1559 }
1560 testClient(t, handler, wrapAgent, "v1v2")
1561
1562 require.Len(t, jar.getCookiesByHost("example.com"), 3)
1563 })
1564
1565 t.Run("with expiration", func(t *testing.T) {
1566 t.Parallel()
1567 handler := func(c fiber.Ctx) error {
1568 c.Cookie(&fiber.Cookie{
1569 Name: "k4",
1570 Value: "v4",
1571 Expires: time.Now().Add(1 * time.Nanosecond),
1572 })
1573 return c.SendString(
1574 c.Cookies("k1") + c.Cookies("k2") + c.Cookies("k3"),
1575 )
1576 }
1577
1578 jar := AcquireCookieJar()
1579 defer ReleaseCookieJar(jar)
1580
1581 jar.SetKeyValue("example.com", "k1", "v1")
1582 jar.SetKeyValue("example.com", "k2", "v2")
1583 jar.SetKeyValue("example", "k3", "v3")
1584
1585 wrapAgent := func(c *Client) {
1586 c.SetCookieJar(jar)
1587 }
1588 testClient(t, handler, wrapAgent, "v1v2")
1589
1590 require.Len(t, jar.getCookiesByHost("example.com"), 2)
1591 })
1592

Callers

nothing calls this directly

Calls 13

AcquireCookieJarFunction · 0.85
ReleaseCookieJarFunction · 0.85
testClientFunction · 0.85
SetKeyValueMethod · 0.80
SetCookieJarMethod · 0.80
getCookiesByHostMethod · 0.80
CookieMethod · 0.65
SendStringMethod · 0.65
CookiesMethod · 0.65
LenMethod · 0.65
AddMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected