File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -35,8 +35,10 @@ func Parse(dsn string) (info parsedInfo, err error) {
3535 info .Options = append (info .Options ,
3636 config .WithSecure (uri .Scheme != insecureSchema ),
3737 config .WithEndpoint (uri .Host ),
38- config .WithDatabase (uri .Path ),
3938 )
39+ if uri .Path != "" {
40+ info .Options = append (info .Options , config .WithDatabase (uri .Path ))
41+ }
4042 if uri .User != nil {
4143 password , _ := uri .User .Password ()
4244 info .UserInfo = & UserInfo {
Original file line number Diff line number Diff line change @@ -124,3 +124,15 @@ func TestParseConnectionString(t *testing.T) {
124124 })
125125 }
126126}
127+
128+ func TestParseConnectionStringEmptyDatabase (t * testing.T ) {
129+ info , err := Parse ("grpc://ydb-ru.yandex.net:2135" )
130+ if err != nil {
131+ t .Fatalf ("Received unexpected error:\n %+v" , err )
132+ }
133+ c := config .New (config .WithDatabase ("mydb" ))
134+ c = c .With (info .Options ... )
135+ require .Equal (t , false , c .Secure ())
136+ require .Equal (t , "ydb-ru.yandex.net:2135" , c .Endpoint ())
137+ require .Equal (t , "mydb" , c .Database ())
138+ }
You can’t perform that action at this time.
0 commit comments