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

Function Benchmark_CookieBinder_Bind

binder/cookie_test.go:52–87  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

50}
51
52func Benchmark_CookieBinder_Bind(b *testing.B) {
53 b.ReportAllocs()
54
55 binder := &CookieBinding{
56 EnableSplitting: true,
57 }
58
59 type User struct {
60 Name string `query:"name"`
61 Posts []string `query:"posts"`
62 Age int `query:"age"`
63 }
64 var user User
65
66 req := fasthttp.AcquireRequest()
67 b.Cleanup(func() {
68 fasthttp.ReleaseRequest(req)
69 })
70
71 req.Header.SetCookie("name", "john")
72 req.Header.SetCookie("age", "42")
73 req.Header.SetCookie("posts", "post1,post2,post3")
74
75 var err error
76 for b.Loop() {
77 err = binder.Bind(req, &user)
78 }
79
80 require.NoError(b, err)
81 require.Equal(b, "john", user.Name)
82 require.Equal(b, 42, user.Age)
83 require.Len(b, user.Posts, 3)
84 require.Contains(b, user.Posts, "post1")
85 require.Contains(b, user.Posts, "post2")
86 require.Contains(b, user.Posts, "post3")
87}
88
89func Test_CookieBinder_Bind_ParseError(t *testing.T) {
90 b := &CookieBinding{}

Callers

nothing calls this directly

Calls 4

BindMethod · 0.95
ContainsMethod · 0.80
LenMethod · 0.65
SetCookieMethod · 0.45

Tested by

no test coverage detected