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

Function TestBindUri

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

Source from the content-addressed store, hash-verified

310}
311
312func TestBindUri(t *testing.T) {
313 DefaultWriter = os.Stdout
314 router := New()
315
316 type Person struct {
317 Name string `uri:"name" binding:"required"`
318 ID string `uri:"id" binding:"required"`
319 }
320 router.Handle(http.MethodGet, "/rest/:name/:id", func(c *Context) {
321 var person Person
322 require.NoError(t, c.BindUri(&person))
323 assert.NotEmpty(t, person.Name)
324 assert.NotEmpty(t, person.ID)
325 c.String(http.StatusOK, "BindUri test OK")
326 })
327
328 path, _ := exampleFromPath("/rest/:name/:id")
329 w := PerformRequest(router, http.MethodGet, path)
330 assert.Equal(t, "BindUri test OK", w.Body.String())
331 assert.Equal(t, http.StatusOK, w.Code)
332}
333
334func TestBindUriError(t *testing.T) {
335 DefaultWriter = os.Stdout

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
exampleFromPathFunction · 0.85
PerformRequestFunction · 0.85
HandleMethod · 0.65
BindUriMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected