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

Function Test_Bind_All

bind_test.go:2658–2804  ·  view source on GitHub ↗

go test -run Test_Bind_All

(t *testing.T)

Source from the content-addressed store, hash-verified

2656
2657// go test -run Test_Bind_All
2658func Test_Bind_All(t *testing.T) {
2659 t.Parallel()
2660 type User struct {
2661 Avatar *multipart.FileHeader `form:"avatar"`
2662 Name string `query:"name" json:"name" form:"name"`
2663 Email string `json:"email" form:"email"`
2664 Role string `header:"X-User-Role"`
2665 SessionID string `json:"session_id" cookie:"session_id"`
2666 ID int `uri:"id" query:"id" json:"id" form:"id"`
2667 }
2668 newBind := func(app *App) *Bind {
2669 return &Bind{
2670 ctx: app.AcquireCtx(&fasthttp.RequestCtx{}),
2671 }
2672 }
2673
2674 defaultConfig := func() *RequestConfig {
2675 return &RequestConfig{
2676 ContentType: MIMEApplicationJSON,
2677 Body: []byte(`{"name":"john", "email": "john@doe.com", "session_id": "abc1234", "id": 1}`),
2678 Headers: map[string]string{
2679 "X-User-Role": "admin",
2680 },
2681 Cookies: map[string]string{
2682 "session_id": "abc123",
2683 },
2684 Query: "id=1&name=john",
2685 }
2686 }
2687
2688 tests := []struct {
2689 out any
2690 expected *User
2691 config *RequestConfig
2692 name string
2693 wantErr bool
2694 }{
2695 {
2696 name: "Invalid output type",
2697 out: 123,
2698 wantErr: true,
2699 },
2700 {
2701 name: "Successful binding",
2702 out: new(User),
2703 config: defaultConfig(),
2704 expected: &User{
2705 ID: 1,
2706 Name: "john",
2707 Email: "john@doe.com",
2708 Role: "admin",
2709 SessionID: "abc1234",
2710 },
2711 },
2712 {
2713 name: "Missing fields (partial JSON only)",
2714 out: new(User),
2715 config: &RequestConfig{

Callers

nothing calls this directly

Calls 5

AcquireCtxMethod · 0.80
ApplyToMethod · 0.80
NewFunction · 0.70
AllMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected