9
9
)
10
10
11
11
func TestFormatDSN (t * testing.T ) {
12
- dsn := "databend+https://username:password@tn3ftqihs.ch.aws-us-east-2.default.databend.com/test?role=test_role&empty_field_as=null&timeout=1s&wait_time_secs=10&max_rows_in_buffer=5000000&max_rows_per_page=10000&tls_config=tls-settings&warehouse=wh"
12
+ dsn := "databend+https://username:password@tn3ftqihs.ch.aws-us-east-2.default.databend.com/test?role=test_role&empty_field_as=null&timeout=1s&wait_time_secs=10&max_rows_in_buffer=5000000&max_rows_per_page=10000&tls_config=tls-settings&warehouse=wh&sessionParam1=sessionValue1 "
13
13
cfg , err := ParseDSN (dsn )
14
14
require .Nil (t , err )
15
15
@@ -22,13 +22,46 @@ func TestFormatDSN(t *testing.T) {
22
22
assert .Equal (t , int64 (10 ), cfg .WaitTimeSecs )
23
23
assert .Equal (t , int64 (5000000 ), cfg .MaxRowsInBuffer )
24
24
assert .Equal (t , "test_role" , cfg .Role )
25
+ assert .Equal (t , "sessionValue1" , cfg .Params ["sessionParam1" ])
25
26
26
27
dsn1 := cfg .FormatDSN ()
27
28
cfg1 , err := ParseDSN (dsn1 )
28
29
require .Nil (t , err )
29
30
assert .Equal (t , cfg , cfg1 )
30
31
}
31
32
33
+ func TestParseDSNWithParams (t * testing.T ) {
34
+ // Create a new Config with some params
35
+ cfg := NewConfig ()
36
+ cfg .Params ["param1" ] = "value1"
37
+ cfg .Params ["param2" ] = "value2"
38
+
39
+ // Generate DSN string
40
+ dsn := cfg .FormatDSN ()
41
+
42
+ // Parse the DSN string
43
+ parsedCfg , err := ParseDSN (dsn )
44
+ require .NoError (t , err )
45
+
46
+ // Check that the parsed Config includes the params
47
+ assert .Equal (t , "value1" , parsedCfg .Params ["param1" ])
48
+ assert .Equal (t , "value2" , parsedCfg .Params ["param2" ])
49
+ }
50
+
51
+ func TestFormatDSNWithParams (t * testing.T ) {
52
+ // Create a new Config with some params
53
+ cfg := NewConfig ()
54
+ cfg .Params ["param1" ] = "value1"
55
+ cfg .Params ["param2" ] = "value2"
56
+
57
+ // Call FormatDSN
58
+ dsn := cfg .FormatDSN ()
59
+
60
+ // Check that the DSN includes the params
61
+ assert .Contains (t , dsn , "param1=value1" )
62
+ assert .Contains (t , dsn , "param2=value2" )
63
+ }
64
+
32
65
func TestParseDSN (t * testing.T ) {
33
66
t .Run ("test simple dns parse" , func (t * testing.T ) {
34
67
dsn := "databend+http://app.databend.com:8000/test?tenant=tn&warehouse=wh&timeout=1s&wait_time_secs=10&max_rows_in_buffer=5000000&max_rows_per_page=10000&tls_config=tls-settings&access_token_file=/tmp/file1"
0 commit comments