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

Function Test_Bind_All_StructValidator

bind_test.go:2856–2875  ·  view source on GitHub ↗

go test -run Test_Bind_All_StructValidator

(t *testing.T)

Source from the content-addressed store, hash-verified

2854
2855// go test -run Test_Bind_All_StructValidator
2856func Test_Bind_All_StructValidator(t *testing.T) {
2857 t.Parallel()
2858 app := New(Config{StructValidator: &structValidator{}})
2859
2860 // Success case: name comes from body only
2861 ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
2862 ctx.Request().Header.SetContentType(MIMEApplicationJSON)
2863 ctx.Request().SetBody([]byte(`{"name":"john"}`))
2864 sq := new(simpleQuery)
2865 require.NoError(t, (&Bind{ctx: ctx}).All(sq))
2866 require.Equal(t, "john", sq.Name)
2867
2868 // Failure: missing name everywhere
2869 ctxFail := app.AcquireCtx(&fasthttp.RequestCtx{})
2870 ctxFail.Request().Header.SetContentType(MIMEApplicationJSON)
2871 ctxFail.Request().SetBody([]byte(`{}`))
2872 sqFail := new(simpleQuery)
2873 err := (&Bind{ctx: ctxFail}).WithoutAutoHandling().All(sqFail)
2874 require.EqualError(t, err, "you should have entered right name")
2875}
2876
2877// go test -v -run=^$ -bench=Benchmark_Bind_All -benchmem -count=4
2878func BenchmarkBind_All(b *testing.B) {

Callers

nothing calls this directly

Calls 5

AcquireCtxMethod · 0.80
WithoutAutoHandlingMethod · 0.80
NewFunction · 0.70
RequestMethod · 0.65
AllMethod · 0.65

Tested by

no test coverage detected