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

Function Test_BindError_All

bind_test.go:365–390  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

363}
364
365func Test_BindError_All(t *testing.T) {
366 t.Parallel()
367
368 type Req struct {
369 Name string `json:"name"`
370 ID int `uri:"id" json:"id"`
371 }
372
373 t.Run("URIFailsFirst", func(t *testing.T) {
374 t.Parallel()
375 app := New()
376 app.Get("/users/:id", func(ctx Ctx) error {
377 err := ctx.Bind().All(new(Req))
378 require.Error(t, err)
379 var be *BindError
380 require.ErrorAs(t, err, &be)
381 require.Equal(t, BindSourceURI, be.Source)
382 require.ErrorAs(t, err, &MultiError{})
383 return nil
384 })
385 req := httptest.NewRequest(http.MethodGet, "/users/notanint", bytes.NewReader([]byte(`{"name":"ok"}`)))
386 req.Header.Set("Content-Type", MIMEApplicationJSON)
387 _, err := app.Test(req)
388 require.NoError(t, err)
389 })
390}
391
392// go test -run Test_Bind_Query -v
393func Test_Bind_Query(t *testing.T) {

Callers

nothing calls this directly

Calls 7

TestMethod · 0.80
NewFunction · 0.70
GetMethod · 0.65
AllMethod · 0.65
BindMethod · 0.65
ErrorMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected