Skip to content

Commit 4a8e23f

Browse files
authored
fix: session params config (#124)
1 parent be68ac3 commit 4a8e23f

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

dsn.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ func (cfg *Config) FormatDSN() string {
141141
} else {
142142
query.Set("empty_field_as", "string")
143143
}
144+
// Add Params to the query
145+
for k, v := range cfg.Params {
146+
query.Set(k, v)
147+
}
144148

145149
u.RawQuery = query.Encode()
146150
return u.String()

dsn_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
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"
1313
cfg, err := ParseDSN(dsn)
1414
require.Nil(t, err)
1515

@@ -22,13 +22,46 @@ func TestFormatDSN(t *testing.T) {
2222
assert.Equal(t, int64(10), cfg.WaitTimeSecs)
2323
assert.Equal(t, int64(5000000), cfg.MaxRowsInBuffer)
2424
assert.Equal(t, "test_role", cfg.Role)
25+
assert.Equal(t, "sessionValue1", cfg.Params["sessionParam1"])
2526

2627
dsn1 := cfg.FormatDSN()
2728
cfg1, err := ParseDSN(dsn1)
2829
require.Nil(t, err)
2930
assert.Equal(t, cfg, cfg1)
3031
}
3132

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+
3265
func TestParseDSN(t *testing.T) {
3366
t.Run("test simple dns parse", func(t *testing.T) {
3467
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

Comments
 (0)