From d756ec1b68dd8d86a4be0c45258c76b448270fb2 Mon Sep 17 00:00:00 2001 From: RW Date: Mon, 26 May 2025 21:45:58 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20chore:=20Add=20URI=20Test=20case?= =?UTF-8?q?=20for=20Test=5FCtx=5FBinders=20(#3480)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add Uri Test case for Test_Ctx_Binders --- ctx_test.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/ctx_test.go b/ctx_test.go index 82516f1c..08113efd 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -1400,10 +1400,10 @@ func Test_Ctx_Binders(t *testing.T) { type TestStruct struct { Name string - NameWithDefault string `json:"name2" xml:"Name2" form:"name2" cookie:"name2" query:"name2" params:"name2" header:"Name2"` + NameWithDefault string `json:"name2" xml:"Name2" form:"name2" cookie:"name2" query:"name2" uri:"name2" header:"Name2"` TestEmbeddedStruct Class int - ClassWithDefault int `json:"class2" xml:"Class2" form:"class2" cookie:"class2" query:"class2" params:"class2" header:"Class2"` + ClassWithDefault int `json:"class2" xml:"Class2" form:"class2" cookie:"class2" query:"class2" uri:"class2" header:"Class2"` } withValues := func(t *testing.T, actionFn func(c Ctx, testStruct *TestStruct) error) { @@ -1469,16 +1469,26 @@ func Test_Ctx_Binders(t *testing.T) { return c.Bind().Query(testStruct) }) }) + t.Run("URI", func(t *testing.T) { - t.Skip("URI is not ready for v3") - //nolint:gocritic // TODO: uncomment - // t.Parallel() - // withValues(t, func(c Ctx, testStruct *TestStruct) error { - // c.Route().Params = []string{"name", "name2", "class", "class2"} - // c.Params().value = [30]string{"foo", "bar", "111", "222"} - // return c.Bind().URI(testStruct) - // }) + t.Parallel() + + c := app.AcquireCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck,forcetypeassert // not needed + defer app.ReleaseCtx(c) + + c.route = &Route{Params: []string{"name", "name2", "class", "class2"}} + c.values = [maxParams]string{"foo", "bar", "111", "222"} + + testStruct := new(TestStruct) + + require.NoError(t, c.Bind().URI(testStruct)) + require.Equal(t, "foo", testStruct.Name) + require.Equal(t, 111, testStruct.Class) + require.Equal(t, "bar", testStruct.NameWithDefault) + require.Equal(t, 222, testStruct.ClassWithDefault) + require.Nil(t, testStruct.TestEmbeddedStruct.Names) }) + t.Run("ReqHeader", func(t *testing.T) { t.Parallel() withValues(t, func(c Ctx, testStruct *TestStruct) error {