@@ -8,12 +8,14 @@ import (
88
99 "github.com/ydb-platform/ydb-go-sdk/v3/config"
1010 "github.com/ydb-platform/ydb-go-sdk/v3/internal/bind"
11- "github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql"
11+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/connector"
12+ querySql "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/conn"
13+ tableSql "github.com/ydb-platform/ydb-go-sdk/v3/internal/table/conn"
1214)
1315
1416func TestParse (t * testing.T ) {
15- newConnector := func (opts ... xsql. ConnectorOption ) * xsql .Connector {
16- c := & xsql .Connector {}
17+ newConnector := func (opts ... connector. Option ) * connector .Connector {
18+ c := & connector .Connector {}
1719 for _ , opt := range opts {
1820 if opt != nil {
1921 if err := opt .Apply (c ); err != nil {
@@ -24,6 +26,12 @@ func TestParse(t *testing.T) {
2426
2527 return c
2628 }
29+ newTableConn := func (opts ... tableSql.Option ) * tableSql.Conn {
30+ return tableSql .New (context .Background (), nil , nil , opts ... )
31+ }
32+ newQueryConn := func (opts ... querySql.Option ) * querySql.Conn {
33+ return querySql .New (context .Background (), nil , nil , opts ... )
34+ }
2735 compareConfigs := func (t * testing.T , lhs , rhs * config.Config ) {
2836 require .Equal (t , lhs .Secure (), rhs .Secure ())
2937 require .Equal (t , lhs .Endpoint (), rhs .Endpoint ())
@@ -32,22 +40,9 @@ func TestParse(t *testing.T) {
3240 for _ , tt := range []struct {
3341 dsn string
3442 opts []config.Option
35- connectorOpts []xsql. ConnectorOption
43+ connectorOpts []connector. Option
3644 err error
3745 }{
38- {
39- dsn : "grpc://localhost:2135/local?go_fake_tx=scripting,scheme" ,
40- opts : []config.Option {
41- config .WithSecure (false ),
42- config .WithEndpoint ("localhost:2135" ),
43- config .WithDatabase ("/local" ),
44- },
45- connectorOpts : []xsql.ConnectorOption {
46- xsql .WithFakeTx (xsql .ScriptingQueryMode ),
47- xsql .WithFakeTx (xsql .SchemeQueryMode ),
48- },
49- err : nil ,
50- },
5146 {
5247 dsn : "grpc://localhost:2135/local" ,
5348 opts : []config.Option {
@@ -75,8 +70,8 @@ func TestParse(t *testing.T) {
7570 config .WithEndpoint ("localhost:2135" ),
7671 config .WithDatabase ("/local" ),
7772 },
78- connectorOpts : []xsql. ConnectorOption {
79- xsql .WithDefaultQueryMode (xsql .ScriptingQueryMode ),
73+ connectorOpts : []connector. Option {
74+ connector .WithDefaultQueryMode (tableSql .ScriptingQueryMode ),
8075 },
8176 err : nil ,
8277 },
@@ -87,9 +82,9 @@ func TestParse(t *testing.T) {
8782 config .WithEndpoint ("localhost:2135" ),
8883 config .WithDatabase ("/local" ),
8984 },
90- connectorOpts : []xsql. ConnectorOption {
91- xsql .WithDefaultQueryMode (xsql .ScriptingQueryMode ),
92- xsql . WithTablePathPrefix ( "path/to/tables" ),
85+ connectorOpts : []connector. Option {
86+ connector .WithDefaultQueryMode (tableSql .ScriptingQueryMode ),
87+ connector . WithQueryBind ( bind . TablePathPrefix ( "path/to/tables" ) ),
9388 },
9489 err : nil ,
9590 },
@@ -100,10 +95,10 @@ func TestParse(t *testing.T) {
10095 config .WithEndpoint ("localhost:2135" ),
10196 config .WithDatabase ("/local" ),
10297 },
103- connectorOpts : []xsql. ConnectorOption {
104- xsql .WithDefaultQueryMode (xsql .ScriptingQueryMode ),
105- xsql . WithTablePathPrefix ( "path/to/tables" ),
106- xsql .WithQueryBind (bind.NumericArgs {}),
98+ connectorOpts : []connector. Option {
99+ connector .WithDefaultQueryMode (tableSql .ScriptingQueryMode ),
100+ connector . WithQueryBind ( bind . TablePathPrefix ( "path/to/tables" ) ),
101+ connector .WithQueryBind (bind.NumericArgs {}),
107102 },
108103 err : nil ,
109104 },
@@ -114,10 +109,10 @@ func TestParse(t *testing.T) {
114109 config .WithEndpoint ("localhost:2135" ),
115110 config .WithDatabase ("/local" ),
116111 },
117- connectorOpts : []xsql. ConnectorOption {
118- xsql .WithDefaultQueryMode (xsql .ScriptingQueryMode ),
119- xsql . WithTablePathPrefix ( "path/to/tables" ),
120- xsql .WithQueryBind (bind.PositionalArgs {}),
112+ connectorOpts : []connector. Option {
113+ connector .WithDefaultQueryMode (tableSql .ScriptingQueryMode ),
114+ connector . WithQueryBind ( bind . TablePathPrefix ( "path/to/tables" ) ),
115+ connector .WithQueryBind (bind.PositionalArgs {}),
121116 },
122117 err : nil ,
123118 },
@@ -128,10 +123,10 @@ func TestParse(t *testing.T) {
128123 config .WithEndpoint ("localhost:2135" ),
129124 config .WithDatabase ("/local" ),
130125 },
131- connectorOpts : []xsql. ConnectorOption {
132- xsql .WithDefaultQueryMode (xsql .ScriptingQueryMode ),
133- xsql . WithTablePathPrefix ( "path/to/tables" ),
134- xsql .WithQueryBind (bind.AutoDeclare {}),
126+ connectorOpts : []connector. Option {
127+ connector .WithDefaultQueryMode (tableSql .ScriptingQueryMode ),
128+ connector . WithQueryBind ( bind . TablePathPrefix ( "path/to/tables" ) ),
129+ connector .WithQueryBind (bind.AutoDeclare {}),
135130 },
136131 err : nil ,
137132 },
@@ -142,9 +137,9 @@ func TestParse(t *testing.T) {
142137 config .WithEndpoint ("localhost:2135" ),
143138 config .WithDatabase ("/local" ),
144139 },
145- connectorOpts : []xsql. ConnectorOption {
146- xsql .WithDefaultQueryMode (xsql .ScriptingQueryMode ),
147- xsql . WithTablePathPrefix ( "path/to/tables" ),
140+ connectorOpts : []connector. Option {
141+ connector .WithDefaultQueryMode (tableSql .ScriptingQueryMode ),
142+ connector . WithQueryBind ( bind . TablePathPrefix ( "path/to/tables" ) ),
148143 },
149144 err : nil ,
150145 },
@@ -155,11 +150,24 @@ func TestParse(t *testing.T) {
155150 config .WithEndpoint ("localhost:2135" ),
156151 config .WithDatabase ("/local" ),
157152 },
158- connectorOpts : []xsql.ConnectorOption {
159- xsql .WithDefaultQueryMode (xsql .ScriptingQueryMode ),
160- xsql .WithTablePathPrefix ("path/to/tables" ),
161- xsql .WithQueryBind (bind.PositionalArgs {}),
162- xsql .WithQueryBind (bind.AutoDeclare {}),
153+ connectorOpts : []connector.Option {
154+ connector .WithDefaultQueryMode (tableSql .ScriptingQueryMode ),
155+ connector .WithQueryBind (bind .TablePathPrefix ("path/to/tables" )),
156+ connector .WithQueryBind (bind.PositionalArgs {}),
157+ connector .WithQueryBind (bind.AutoDeclare {}),
158+ },
159+ err : nil ,
160+ },
161+ {
162+ dsn : "grpc://localhost:2135/local?go_fake_tx=scripting,scheme" ,
163+ opts : []config.Option {
164+ config .WithSecure (false ),
165+ config .WithEndpoint ("localhost:2135" ),
166+ config .WithDatabase ("/local" ),
167+ },
168+ connectorOpts : []connector.Option {
169+ connector .WithFakeTx (tableSql .ScriptingQueryMode ),
170+ connector .WithFakeTx (tableSql .SchemeQueryMode ),
163171 },
164172 err : nil ,
165173 },
@@ -172,7 +180,20 @@ func TestParse(t *testing.T) {
172180 require .NoError (t , err )
173181 d , err := newConnectionFromOptions (context .Background (), opts ... )
174182 require .NoError (t , err )
175- require .Equal (t , newConnector (tt .connectorOpts ... ), newConnector (d .databaseSQLOptions ... ))
183+ exp := newConnector (tt .connectorOpts ... )
184+ act := newConnector (d .databaseSQLOptions ... )
185+ t .Run ("tableOptions" , func (t * testing.T ) {
186+ require .Equal (t , newTableConn (exp .TableOpts ... ), newTableConn (act .TableOpts ... ))
187+ })
188+ t .Run ("queryOptions" , func (t * testing.T ) {
189+ require .Equal (t , newQueryConn (exp .QueryOpts ... ), newQueryConn (act .QueryOpts ... ))
190+ })
191+ exp .TableOpts = nil
192+ exp .QueryOpts = nil
193+ act .TableOpts = nil
194+ act .QueryOpts = nil
195+ require .Equal (t , exp .Bindings (), act .Bindings ())
196+ require .Equal (t , exp , act )
176197 compareConfigs (t , config .New (tt .opts ... ), d .config )
177198 }
178199 })
0 commit comments