Helper functions
(ctx context.Context, engine storepb.Engine, container *testcontainer.Container, testDBName string)
| 194 | |
| 195 | // Helper functions |
| 196 | func getDriver(ctx context.Context, engine storepb.Engine, container *testcontainer.Container, testDBName string) (db.Driver, error) { |
| 197 | var dbDatabase string |
| 198 | switch engine { |
| 199 | case storepb.Engine_MYSQL: |
| 200 | dbDatabase = testDBName |
| 201 | case storepb.Engine_POSTGRES: |
| 202 | dbDatabase = "postgres" |
| 203 | case storepb.Engine_ORACLE: |
| 204 | dbDatabase = "FREEPDB1" |
| 205 | case storepb.Engine_MSSQL: |
| 206 | dbDatabase = "master" |
| 207 | default: |
| 208 | dbDatabase = "" |
| 209 | } |
| 210 | |
| 211 | config := db.ConnectionConfig{ |
| 212 | DataSource: &storepb.DataSource{ |
| 213 | Host: container.GetHost(), |
| 214 | Port: container.GetPort(), |
| 215 | Username: "root", |
| 216 | Database: dbDatabase, |
| 217 | }, |
| 218 | ConnectionContext: db.ConnectionContext{ |
| 219 | DatabaseName: dbDatabase, |
| 220 | }, |
| 221 | Password: "root", |
| 222 | } |
| 223 | |
| 224 | // Special handling for different engines based on testcontainer setup |
| 225 | switch engine { |
| 226 | case storepb.Engine_MYSQL: |
| 227 | config.DataSource.Username = "root" |
| 228 | config.Password = "root-password" |
| 229 | case storepb.Engine_POSTGRES: |
| 230 | config.DataSource.Username = "postgres" |
| 231 | config.Password = "root-password" |
| 232 | case storepb.Engine_ORACLE: |
| 233 | config.DataSource.Username = "testuser" |
| 234 | config.Password = "testpass" |
| 235 | config.DataSource.Database = "" |
| 236 | config.ConnectionContext.DatabaseName = "" |
| 237 | // Set service name for Oracle |
| 238 | config.DataSource.ServiceName = "FREEPDB1" |
| 239 | case storepb.Engine_MSSQL: |
| 240 | config.DataSource.Username = "sa" |
| 241 | config.Password = "Test123!" |
| 242 | default: |
| 243 | // Use default config for other engines |
| 244 | } |
| 245 | |
| 246 | driver, err := db.Open(ctx, engine, config) |
| 247 | if err != nil { |
| 248 | return nil, err |
| 249 | } |
| 250 | |
| 251 | return driver, nil |
| 252 | } |
| 253 |
no test coverage detected