1- package xsql
1+ package ydb
22
33import (
4+ "context"
45 "testing"
56
67 "github.com/stretchr/testify/require"
78
89 "github.com/ydb-platform/ydb-go-sdk/v3/config"
910 "github.com/ydb-platform/ydb-go-sdk/v3/internal/bind"
11+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql"
1012)
1113
1214func TestParse (t * testing.T ) {
13- newConnector := func (opts ... ConnectorOption ) * Connector {
14- c := & Connector {}
15+ newConnector := func (opts ... xsql. ConnectorOption ) * xsql. Connector {
16+ c := & xsql. Connector {}
1517 for _ , opt := range opts {
1618 if opt != nil {
1719 if err := opt .Apply (c ); err != nil {
@@ -30,7 +32,7 @@ func TestParse(t *testing.T) {
3032 for _ , tt := range []struct {
3133 dsn string
3234 opts []config.Option
33- connectorOpts []ConnectorOption
35+ connectorOpts []xsql. ConnectorOption
3436 err error
3537 }{
3638 {
@@ -40,9 +42,9 @@ func TestParse(t *testing.T) {
4042 config .WithEndpoint ("localhost:2135" ),
4143 config .WithDatabase ("/local" ),
4244 },
43- connectorOpts : []ConnectorOption {
44- WithFakeTx (ScriptingQueryMode ),
45- WithFakeTx (SchemeQueryMode ),
45+ connectorOpts : []xsql. ConnectorOption {
46+ xsql . WithFakeTx (xsql . ScriptingQueryMode ),
47+ xsql . WithFakeTx (xsql . SchemeQueryMode ),
4648 },
4749 err : nil ,
4850 },
@@ -73,8 +75,8 @@ func TestParse(t *testing.T) {
7375 config .WithEndpoint ("localhost:2135" ),
7476 config .WithDatabase ("/local" ),
7577 },
76- connectorOpts : []ConnectorOption {
77- WithDefaultQueryMode (ScriptingQueryMode ),
78+ connectorOpts : []xsql. ConnectorOption {
79+ xsql . WithDefaultQueryMode (xsql . ScriptingQueryMode ),
7880 },
7981 err : nil ,
8082 },
@@ -85,9 +87,9 @@ func TestParse(t *testing.T) {
8587 config .WithEndpoint ("localhost:2135" ),
8688 config .WithDatabase ("/local" ),
8789 },
88- connectorOpts : []ConnectorOption {
89- WithDefaultQueryMode (ScriptingQueryMode ),
90- WithTablePathPrefix ("path/to/tables" ),
90+ connectorOpts : []xsql. ConnectorOption {
91+ xsql . WithDefaultQueryMode (xsql . ScriptingQueryMode ),
92+ xsql . WithTablePathPrefix ("path/to/tables" ),
9193 },
9294 err : nil ,
9395 },
@@ -98,10 +100,10 @@ func TestParse(t *testing.T) {
98100 config .WithEndpoint ("localhost:2135" ),
99101 config .WithDatabase ("/local" ),
100102 },
101- connectorOpts : []ConnectorOption {
102- WithDefaultQueryMode (ScriptingQueryMode ),
103- WithTablePathPrefix ("path/to/tables" ),
104- WithQueryBind (bind.NumericArgs {}),
103+ connectorOpts : []xsql. ConnectorOption {
104+ xsql . WithDefaultQueryMode (xsql . ScriptingQueryMode ),
105+ xsql . WithTablePathPrefix ("path/to/tables" ),
106+ xsql . WithQueryBind (bind.NumericArgs {}),
105107 },
106108 err : nil ,
107109 },
@@ -112,10 +114,10 @@ func TestParse(t *testing.T) {
112114 config .WithEndpoint ("localhost:2135" ),
113115 config .WithDatabase ("/local" ),
114116 },
115- connectorOpts : []ConnectorOption {
116- WithDefaultQueryMode (ScriptingQueryMode ),
117- WithTablePathPrefix ("path/to/tables" ),
118- WithQueryBind (bind.PositionalArgs {}),
117+ connectorOpts : []xsql. ConnectorOption {
118+ xsql . WithDefaultQueryMode (xsql . ScriptingQueryMode ),
119+ xsql . WithTablePathPrefix ("path/to/tables" ),
120+ xsql . WithQueryBind (bind.PositionalArgs {}),
119121 },
120122 err : nil ,
121123 },
@@ -126,10 +128,10 @@ func TestParse(t *testing.T) {
126128 config .WithEndpoint ("localhost:2135" ),
127129 config .WithDatabase ("/local" ),
128130 },
129- connectorOpts : []ConnectorOption {
130- WithDefaultQueryMode (ScriptingQueryMode ),
131- WithTablePathPrefix ("path/to/tables" ),
132- WithQueryBind (bind.AutoDeclare {}),
131+ connectorOpts : []xsql. ConnectorOption {
132+ xsql . WithDefaultQueryMode (xsql . ScriptingQueryMode ),
133+ xsql . WithTablePathPrefix ("path/to/tables" ),
134+ xsql . WithQueryBind (bind.AutoDeclare {}),
133135 },
134136 err : nil ,
135137 },
@@ -140,9 +142,9 @@ func TestParse(t *testing.T) {
140142 config .WithEndpoint ("localhost:2135" ),
141143 config .WithDatabase ("/local" ),
142144 },
143- connectorOpts : []ConnectorOption {
144- WithDefaultQueryMode (ScriptingQueryMode ),
145- WithTablePathPrefix ("path/to/tables" ),
145+ connectorOpts : []xsql. ConnectorOption {
146+ xsql . WithDefaultQueryMode (xsql . ScriptingQueryMode ),
147+ xsql . WithTablePathPrefix ("path/to/tables" ),
146148 },
147149 err : nil ,
148150 },
@@ -153,23 +155,25 @@ func TestParse(t *testing.T) {
153155 config .WithEndpoint ("localhost:2135" ),
154156 config .WithDatabase ("/local" ),
155157 },
156- connectorOpts : []ConnectorOption {
157- WithDefaultQueryMode (ScriptingQueryMode ),
158- WithTablePathPrefix ("path/to/tables" ),
159- WithQueryBind (bind.PositionalArgs {}),
160- WithQueryBind (bind.AutoDeclare {}),
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 {}),
161163 },
162164 err : nil ,
163165 },
164166 } {
165167 t .Run ("" , func (t * testing.T ) {
166- opts , connectorOpts , err := Parse (tt .dsn )
168+ opts , err := parseConnectionString (tt .dsn )
167169 if tt .err != nil {
168170 require .ErrorIs (t , err , tt .err )
169171 } else {
170172 require .NoError (t , err )
171- require .Equal (t , newConnector (tt .connectorOpts ... ), newConnector (connectorOpts ... ))
172- compareConfigs (t , config .New (tt .opts ... ), config .New (opts ... ))
173+ d , err := newConnectionFromOptions (context .Background (), opts ... )
174+ require .NoError (t , err )
175+ require .Equal (t , newConnector (tt .connectorOpts ... ), newConnector (d .databaseSQLOptions ... ))
176+ compareConfigs (t , config .New (tt .opts ... ), d .config )
173177 }
174178 })
175179 }
0 commit comments