MCPcopy
hub / github.com/gin-gonic/gin / TestHeaderBinding

Function TestHeaderBinding

binding/binding_test.go:790–813  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

788}
789
790func TestHeaderBinding(t *testing.T) {
791 h := Header
792 assert.Equal(t, "header", h.Name())
793
794 type tHeader struct {
795 Limit int `header:"limit"`
796 }
797
798 var theader tHeader
799 req := requestWithBody(http.MethodGet, "/", "")
800 req.Header.Add("limit", "1000")
801 require.NoError(t, h.Bind(req, &theader))
802 assert.Equal(t, 1000, theader.Limit)
803
804 req = requestWithBody(http.MethodGet, "/", "")
805 req.Header.Add("fail", `{fail:fail}`)
806
807 type failStruct struct {
808 Fail map[string]any `header:"fail"`
809 }
810
811 err := h.Bind(req, &failStruct{})
812 require.Error(t, err)
813}
814
815func TestUriBinding(t *testing.T) {
816 b := Uri

Callers

nothing calls this directly

Calls 4

requestWithBodyFunction · 0.85
NameMethod · 0.65
BindMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected