github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/table/table_test.go (about)

     1  package table_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  
     8  	"github.com/ydb-platform/ydb-go-sdk/v3/table"
     9  	"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
    10  )
    11  
    12  func TestQueryParameters_String(t *testing.T) {
    13  	for _, tt := range []struct {
    14  		p *table.QueryParameters
    15  		s string
    16  	}{
    17  		{
    18  			p: nil,
    19  			s: `{}`,
    20  		},
    21  		{
    22  			p: table.NewQueryParameters(),
    23  			s: `{}`,
    24  		},
    25  		{
    26  			p: table.NewQueryParameters(
    27  				table.ValueParam("$a", types.TextValue("test")),
    28  			),
    29  			s: `{"$a":"test"u}`,
    30  		},
    31  		{
    32  			p: table.NewQueryParameters(
    33  				table.ValueParam("$a", types.TextValue("test")),
    34  				table.ValueParam("$b", types.BytesValue([]byte("test"))),
    35  			),
    36  			s: `{"$a":"test"u,"$b":"test"}`,
    37  		},
    38  		{
    39  			p: table.NewQueryParameters(
    40  				table.ValueParam("$a", types.TextValue("test")),
    41  				table.ValueParam("$b", types.BytesValue([]byte("test"))),
    42  				table.ValueParam("$c", types.Uint64Value(123456)),
    43  			),
    44  			s: `{"$a":"test"u,"$b":"test","$c":123456ul}`,
    45  		},
    46  		{
    47  			p: table.NewQueryParameters(
    48  				table.ValueParam("$a", types.TextValue("test")),
    49  				table.ValueParam("$b", types.BytesValue([]byte("test"))),
    50  				table.ValueParam("$c", types.Uint64Value(123456)),
    51  				table.ValueParam("$d", types.StructValue(
    52  					types.StructFieldValue("$a", types.TextValue("test")),
    53  					types.StructFieldValue("$b", types.BytesValue([]byte("test"))),
    54  					types.StructFieldValue("$c", types.Uint64Value(123456)),
    55  				)),
    56  			),
    57  			s: "{\"$a\":\"test\"u,\"$b\":\"test\",\"$c\":123456ul,\"$d\":<|`$a`:\"test\"u,`$b`:\"test\",`$c`:123456ul|>}",
    58  		},
    59  	} {
    60  		t.Run("", func(t *testing.T) {
    61  			require.Equal(t, tt.s, tt.p.String())
    62  		})
    63  	}
    64  }