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

Function Test_Ctx_Accepts

ctx_test.go:63–98  ·  view source on GitHub ↗

go test -run Test_Ctx_Accepts

(t *testing.T)

Source from the content-addressed store, hash-verified

61
62// go test -run Test_Ctx_Accepts
63func Test_Ctx_Accepts(t *testing.T) {
64 t.Parallel()
65 app := New(Config{
66 CBOREncoder: cbor.Marshal,
67 CBORDecoder: cbor.Unmarshal,
68 })
69 c := app.AcquireCtx(&fasthttp.RequestCtx{})
70
71 c.Request().Header.Set(HeaderAccept, "text/html,application/xhtml+xml,application/xml;q=0.9")
72 require.Empty(t, c.Accepts(""))
73 require.Empty(t, c.Req().Accepts())
74 require.Equal(t, ".xml", c.Accepts(".xml"))
75 require.Empty(t, c.Accepts(".john"))
76 require.Equal(t, "application/xhtml+xml", c.Accepts("application/xml", "application/xml+rss", "application/yaml", "application/xhtml+xml"), "must use client-preferred mime type")
77
78 c.Request().Header.Set(HeaderAccept, "application/json, text/plain, */*;q=0")
79 require.Empty(t, c.Accepts("html"), "must treat */*;q=0 as not acceptable")
80
81 c.Request().Header.Set(HeaderAccept, "text/*, application/json")
82 require.Equal(t, "html", c.Accepts("html"))
83 require.Equal(t, "text/html", c.Accepts("text/html"))
84 require.Equal(t, "json", c.Req().Accepts("json", "text"))
85 require.Equal(t, "application/json", c.Accepts("application/json"))
86 require.Empty(t, c.Accepts("image/png"))
87 require.Empty(t, c.Accepts("png"))
88
89 c.Request().Header.Set(HeaderAccept, "text/html, application/json")
90 require.Equal(t, "text/*", c.Req().Accepts("text/*"))
91
92 c.Request().Header.Set(HeaderAccept, "*/*")
93 require.Equal(t, "html", c.Accepts("html"))
94
95 c.Request().Header.Del(HeaderAccept)
96 require.Equal(t, "json", c.Accepts("json", "html"))
97 require.Equal(t, "application/json", c.Accepts("application/json", "text/html"))
98}
99
100// go test -run Test_Ctx_AcceptsHelpers
101func Test_Ctx_AcceptsHelpers(t *testing.T) {

Callers

nothing calls this directly

Calls 7

AcquireCtxMethod · 0.80
NewFunction · 0.70
SetMethod · 0.65
RequestMethod · 0.65
AcceptsMethod · 0.65
ReqMethod · 0.65
DelMethod · 0.65

Tested by

no test coverage detected