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

Function TestBindMiddleware

utils_test.go:116–136  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

114}
115
116func TestBindMiddleware(t *testing.T) {
117 var value *bindTestStruct
118 var called bool
119 router := New()
120 router.GET("/", Bind(bindTestStruct{}), func(c *Context) {
121 called = true
122 value = c.MustGet(BindKey).(*bindTestStruct)
123 })
124 PerformRequest(router, http.MethodGet, "/?foo=hola&bar=10")
125 assert.True(t, called)
126 assert.Equal(t, "hola", value.Foo)
127 assert.Equal(t, 10, value.Bar)
128
129 called = false
130 PerformRequest(router, http.MethodGet, "/?foo=hola&bar=1")
131 assert.False(t, called)
132
133 assert.Panics(t, func() {
134 Bind(&bindTestStruct{})
135 })
136}
137
138func TestMarshalXMLforH(t *testing.T) {
139 h := H{

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
BindFunction · 0.85
PerformRequestFunction · 0.85
MustGetMethod · 0.80
GETMethod · 0.65

Tested by

no test coverage detected