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

Function Test_Bind_All_Uri_Precedence

bind_test.go:2807–2835  ·  view source on GitHub ↗

go test -run Test_Bind_All_Uri_Precedence

(t *testing.T)

Source from the content-addressed store, hash-verified

2805
2806// go test -run Test_Bind_All_Uri_Precedence
2807func Test_Bind_All_Uri_Precedence(t *testing.T) {
2808 t.Parallel()
2809 type User struct {
2810 Name string `json:"name"`
2811 Email string `json:"email"`
2812 ID int `uri:"id" json:"id" query:"id" form:"id"`
2813 }
2814
2815 app := New()
2816
2817 app.Post("/test1/:id", func(c Ctx) error {
2818 d := new(User)
2819 if err := c.Bind().All(d); err != nil {
2820 t.Fatal(err)
2821 }
2822
2823 require.Equal(t, 111, d.ID)
2824 require.Equal(t, "john", d.Name)
2825 require.Equal(t, "john@doe.com", d.Email)
2826 return nil
2827 })
2828
2829 body := strings.NewReader(`{"id": 999, "name": "john", "email": "john@doe.com"}`)
2830 req := httptest.NewRequest(MethodPost, "/test1/111?id=888", body)
2831 req.Header.Set("Content-Type", "application/json")
2832 res, err := app.Test(req)
2833 require.NoError(t, err)
2834 require.Equal(t, 200, res.StatusCode)
2835}
2836
2837// go test -run Test_Bind_All_Query_Precedence
2838func Test_Bind_All_Query_Precedence(t *testing.T) {

Callers

nothing calls this directly

Calls 7

TestMethod · 0.80
NewFunction · 0.70
PostMethod · 0.65
AllMethod · 0.65
BindMethod · 0.65
FatalMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected