@@ -150,6 +150,87 @@ func Test_getGeneralDbConnectionConfigFromMysql_Connection(t *testing.T) {
150
150
})
151
151
}
152
152
153
+ func Test_getGeneralDbConnectionConfigFromMysql_Url_mysql (t * testing.T ) {
154
+ out , err := getGeneralDbConnectionConfigFromMysql (& mgmtv1alpha1.ConnectionConfig_MysqlConfig {
155
+ MysqlConfig : & mgmtv1alpha1.MysqlConnectionConfig {
156
+ ConnectionConfig : & mgmtv1alpha1.MysqlConnectionConfig_Url {
157
+ Url : "mysql://myuser:mypassword@localhost:3306/mydatabase?ssl=true" ,
158
+ },
159
+ },
160
+ }, ptr (uint32 (5 )))
161
+
162
+ assert .NoError (t , err )
163
+ assert .NotNil (t , out )
164
+ assert .Equal (t , out , & GeneralDbConnectConfig {
165
+ Driver : "mysql" ,
166
+ Host : "localhost" ,
167
+ Port : 3306 ,
168
+ Database : "mydatabase" ,
169
+ User : "myuser" ,
170
+ Pass : "mypassword" ,
171
+ Protocol : nil ,
172
+ QueryParams : url.Values {"ssl" : []string {"true" }},
173
+ })
174
+ }
175
+ func Test_getGeneralDbConnectionConfigFromMysql_Url_mysqlx (t * testing.T ) {
176
+ out , err := getGeneralDbConnectionConfigFromMysql (& mgmtv1alpha1.ConnectionConfig_MysqlConfig {
177
+ MysqlConfig : & mgmtv1alpha1.MysqlConnectionConfig {
178
+ ConnectionConfig : & mgmtv1alpha1.MysqlConnectionConfig_Url {
179
+ Url : "mysqlx://myuser:mypassword@localhost:3306/mydatabase?ssl=true" ,
180
+ },
181
+ },
182
+ }, ptr (uint32 (5 )))
183
+
184
+ assert .NoError (t , err )
185
+ assert .NotNil (t , out )
186
+ assert .Equal (t , out , & GeneralDbConnectConfig {
187
+ Driver : "mysqlx" ,
188
+ Host : "localhost" ,
189
+ Port : 3306 ,
190
+ Database : "mydatabase" ,
191
+ User : "myuser" ,
192
+ Pass : "mypassword" ,
193
+ Protocol : nil ,
194
+ QueryParams : url.Values {"ssl" : []string {"true" }},
195
+ })
196
+ }
197
+
198
+ func Test_getGeneralDbConnectionConfigFromMysql_Url_Error (t * testing.T ) {
199
+ _ , err := getGeneralDbConnectionConfigFromMysql (& mgmtv1alpha1.ConnectionConfig_MysqlConfig {
200
+ MysqlConfig : & mgmtv1alpha1.MysqlConnectionConfig {
201
+ ConnectionConfig : & mgmtv1alpha1.MysqlConnectionConfig_Url {
202
+ Url : "mysql://myuser:mypassword/mydatabase?ssl=true" ,
203
+ },
204
+ },
205
+ }, ptr (uint32 (5 )))
206
+
207
+ assert .Error (t , err )
208
+ }
209
+
210
+ func Test_getGeneralDbConnectionConfigFromMysql_Url_NoScheme (t * testing.T ) {
211
+ _ , err := getGeneralDbConnectionConfigFromMysql (& mgmtv1alpha1.ConnectionConfig_MysqlConfig {
212
+ MysqlConfig : & mgmtv1alpha1.MysqlConnectionConfig {
213
+ ConnectionConfig : & mgmtv1alpha1.MysqlConnectionConfig_Url {
214
+ Url : "mysqlxxx://myuser:mypassword@localhost:3306/mydatabase?ssl=true" ,
215
+ },
216
+ },
217
+ }, ptr (uint32 (5 )))
218
+
219
+ assert .Error (t , err )
220
+ }
221
+
222
+ func Test_getGeneralDbConnectionConfigFromMysql_Url_NoPort (t * testing.T ) {
223
+ _ , err := getGeneralDbConnectionConfigFromMysql (& mgmtv1alpha1.ConnectionConfig_MysqlConfig {
224
+ MysqlConfig : & mgmtv1alpha1.MysqlConnectionConfig {
225
+ ConnectionConfig : & mgmtv1alpha1.MysqlConnectionConfig_Url {
226
+ Url : "mysqlxxx://myuser:mypassword@localhost/mydatabase?ssl=true" ,
227
+ },
228
+ },
229
+ }, ptr (uint32 (5 )))
230
+
231
+ assert .Error (t , err )
232
+ }
233
+
153
234
func Test_GeneralDbConnectionConfig_String (t * testing.T ) {
154
235
type testcase struct {
155
236
name string
0 commit comments