go test -run Test_Bind_All_StructValidator
(t *testing.T)
| 2854 | |
| 2855 | // go test -run Test_Bind_All_StructValidator |
| 2856 | func 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 |
| 2878 | func BenchmarkBind_All(b *testing.B) { |
nothing calls this directly
no test coverage detected