github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/dsn/dsn_test.go (about) 1 package dsn 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 "github.com/ydb-platform/ydb-go-sdk/v3/config" 9 ) 10 11 func TestParseConnectionString(t *testing.T) { 12 for _, test := range []struct { 13 connectionString string 14 secure bool 15 endpoint string 16 database string 17 user string 18 password string 19 }{ 20 { 21 "grpc://ydb-ru.yandex.net:2135/?" + 22 "database=/ru/home/gvit/mydb", 23 false, 24 "ydb-ru.yandex.net:2135", 25 "/ru/home/gvit/mydb", 26 "", 27 "", 28 }, 29 { 30 "grpc://ydb-ru.yandex.net:2135/ru/home/gvit/mydb", 31 false, 32 "ydb-ru.yandex.net:2135", 33 "/ru/home/gvit/mydb", 34 "", 35 "", 36 }, 37 { 38 "grpcs://ydb.serverless.yandexcloud.net:2135/?" + 39 "database=/ru-central1/b1g8skpblkos03malf3s/etn02qso4v3isjb00te1", 40 true, 41 "ydb.serverless.yandexcloud.net:2135", 42 "/ru-central1/b1g8skpblkos03malf3s/etn02qso4v3isjb00te1", 43 "", 44 "", 45 }, 46 { 47 "grpcs://ydb.serverless.yandexcloud.net:2135" + 48 "/ru-central1/b1g8skpblkos03malf3s/etn02qso4v3isjb00te1", 49 true, 50 "ydb.serverless.yandexcloud.net:2135", 51 "/ru-central1/b1g8skpblkos03malf3s/etn02qso4v3isjb00te1", 52 "", 53 "", 54 }, 55 { 56 "grpcs://ydb.serverless.yandexcloud.net:2135" + 57 "/ru-central1/b1g8skpblkos03malf3s/etn02qso4v3isjb00te1?database=/ru/home/gvit/mydb", 58 true, 59 "ydb.serverless.yandexcloud.net:2135", 60 "/ru/home/gvit/mydb", 61 "", 62 "", 63 }, 64 { 65 "grpcs://lb.etn03r9df42nb631unbv.ydb.mdb.yandexcloud.net:2135/?" + 66 "database=/ru-central1/b1g8skpblkos03malf3s/etn03r9df42nb631unbv", 67 true, 68 "lb.etn03r9df42nb631unbv.ydb.mdb.yandexcloud.net:2135", 69 "/ru-central1/b1g8skpblkos03malf3s/etn03r9df42nb631unbv", 70 "", 71 "", 72 }, 73 { 74 "grpcs://lb.etn03r9df42nb631unbv.ydb.mdb.yandexcloud.net:2135" + 75 "/ru-central1/b1g8skpblkos03malf3s/etn03r9df42nb631unbv", 76 true, 77 "lb.etn03r9df42nb631unbv.ydb.mdb.yandexcloud.net:2135", 78 "/ru-central1/b1g8skpblkos03malf3s/etn03r9df42nb631unbv", 79 "", 80 "", 81 }, 82 { 83 "grpcs://user:password@lb.etn03r9df42nb631unbv.ydb.mdb.yandexcloud.net:2135" + 84 "/ru-central1/b1g8skpblkos03malf3s/etn03r9df42nb631unbv", 85 true, 86 "lb.etn03r9df42nb631unbv.ydb.mdb.yandexcloud.net:2135", 87 "/ru-central1/b1g8skpblkos03malf3s/etn03r9df42nb631unbv", 88 "user", 89 "password", 90 }, 91 { 92 "abcd://ydb-ru.yandex.net:2135/?database=/ru/home/gvit/mydb", 93 true, 94 "ydb-ru.yandex.net:2135", 95 "/ru/home/gvit/mydb", 96 "", 97 "", 98 }, 99 { 100 "abcd://ydb-ru.yandex.net:2135/ru/home/gvit/mydb", 101 true, 102 "ydb-ru.yandex.net:2135", 103 "/ru/home/gvit/mydb", 104 "", 105 "", 106 }, 107 } { 108 t.Run(test.connectionString, func(t *testing.T) { 109 info, err := Parse(test.connectionString) 110 if err != nil { 111 t.Fatalf("Received unexpected error:\n%+v", err) 112 } 113 c := config.New(info.Options...) 114 require.Equal(t, test.secure, c.Secure()) 115 require.Equal(t, test.endpoint, c.Endpoint()) 116 require.Equal(t, test.database, c.Database()) 117 if test.user != "" { 118 require.NotNil(t, t, info.UserInfo) 119 require.Equal(t, test.user, info.UserInfo.User) 120 require.Equal(t, test.password, info.UserInfo.Password) 121 } else { 122 require.Nil(t, info.UserInfo) 123 } 124 }) 125 } 126 }