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

Function TestShouldBindUri

githubapi_test.go:290–310  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

288}
289
290func TestShouldBindUri(t *testing.T) {
291 DefaultWriter = os.Stdout
292 router := New()
293
294 type Person struct {
295 Name string `uri:"name" binding:"required"`
296 ID string `uri:"id" binding:"required"`
297 }
298 router.Handle(http.MethodGet, "/rest/:name/:id", func(c *Context) {
299 var person Person
300 require.NoError(t, c.ShouldBindUri(&person))
301 assert.NotEmpty(t, person.Name)
302 assert.NotEmpty(t, person.ID)
303 c.String(http.StatusOK, "ShouldBindUri test OK")
304 })
305
306 path, _ := exampleFromPath("/rest/:name/:id")
307 w := PerformRequest(router, http.MethodGet, path)
308 assert.Equal(t, "ShouldBindUri test OK", w.Body.String())
309 assert.Equal(t, http.StatusOK, w.Code)
310}
311
312func TestBindUri(t *testing.T) {
313 DefaultWriter = os.Stdout

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
exampleFromPathFunction · 0.85
PerformRequestFunction · 0.85
ShouldBindUriMethod · 0.80
HandleMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected