From d0c4c2f517e606a48509671bd933904b7b8c5bc2 Mon Sep 17 00:00:00 2001 From: Aleksey Myasnikov Date: Sat, 30 Dec 2023 15:22:41 +0300 Subject: [PATCH] asasalint enable --- .golangci.yml | 1 - sugar/params_go1.18.go | 2 +- sugar/params_go1.18_test.go | 47 +++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c335db109..b8dd86722 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -207,7 +207,6 @@ linters-settings: linters: enable-all: true disable: - - asasalint - bodyclose - containedctx - contextcheck diff --git a/sugar/params_go1.18.go b/sugar/params_go1.18.go index 0e0eeb1e3..2fc73d6cb 100644 --- a/sugar/params_go1.18.go +++ b/sugar/params_go1.18.go @@ -44,7 +44,7 @@ func GenerateDeclareSection[T *table.QueryParameters | []table.ParameterOption | // // Deprecated: use testutil/QueryBind helper func ToYdbParam(param sql.NamedArg) (table.ParameterOption, error) { - params, err := bind.Params([]interface{}{param}) + params, err := bind.Params(param) if err != nil { return nil, xerrors.WithStackTrace(err) } diff --git a/sugar/params_go1.18_test.go b/sugar/params_go1.18_test.go index eaae11419..14a71fb59 100644 --- a/sugar/params_go1.18_test.go +++ b/sugar/params_go1.18_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ydb-platform/ydb-go-sdk/v3/internal/bind" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest" "github.com/ydb-platform/ydb-go-sdk/v3/table" "github.com/ydb-platform/ydb-go-sdk/v3/table/types" "github.com/ydb-platform/ydb-go-sdk/v3/testutil" @@ -270,3 +271,49 @@ func TestGenerateDeclareSection_NamedArg(t *testing.T) { }) } } + +func TestToYdbParam(t *testing.T) { + for _, tt := range []struct { + name string + param sql.NamedArg + ydbParam table.ParameterOption + err error + }{ + { + name: xtest.CurrentFileLine(), + param: sql.Named("a", "b"), + ydbParam: table.ValueParam("$a", types.TextValue("b")), + err: nil, + }, + { + name: xtest.CurrentFileLine(), + param: sql.Named("a", 123), + ydbParam: table.ValueParam("$a", types.Int32Value(123)), + err: nil, + }, + { + name: xtest.CurrentFileLine(), + param: sql.Named("a", types.OptionalValue(types.TupleValue( + types.BytesValue([]byte("test")), + types.TextValue("test"), + types.Uint64Value(123), + ))), + ydbParam: table.ValueParam("$a", types.OptionalValue(types.TupleValue( + types.BytesValue([]byte("test")), + types.TextValue("test"), + types.Uint64Value(123), + ))), + err: nil, + }, + } { + t.Run(tt.name, func(t *testing.T) { + ydbParam, err := ToYdbParam(tt.param) + if tt.err != nil { + require.Error(t, err) + } else { + require.NoError(t, err) + require.Equal(t, tt.ydbParam, ydbParam) + } + }) + } +}