GetOracleContainer creates an Oracle container for testing
(ctx context.Context)
| 208 | |
| 209 | // GetOracleContainer creates an Oracle container for testing |
| 210 | func GetOracleContainer(ctx context.Context) (retC *Container, retErr error) { |
| 211 | req := testcontainers.ContainerRequest{ |
| 212 | Image: "gvenzl/oracle-free:slim", |
| 213 | Env: map[string]string{ |
| 214 | "ORACLE_PASSWORD": "test123", |
| 215 | "APP_USER": "testuser", |
| 216 | "APP_USER_PASSWORD": "testpass", |
| 217 | }, |
| 218 | ExposedPorts: []string{"1521/tcp"}, |
| 219 | WaitingFor: wait.ForLog("DATABASE IS READY TO USE!"). |
| 220 | WithStartupTimeout(10 * time.Minute), |
| 221 | HostConfigModifier: func(hc *container.HostConfig) { |
| 222 | hc.ShmSize = 1 * 1024 * 1024 * 1024 // 1GB shared memory |
| 223 | }, |
| 224 | } |
| 225 | |
| 226 | c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ |
| 227 | ContainerRequest: req, |
| 228 | Started: true, |
| 229 | }) |
| 230 | if err != nil { |
| 231 | return nil, err |
| 232 | } |
| 233 | |
| 234 | host, err := c.Host(ctx) |
| 235 | if err != nil { |
| 236 | return nil, err |
| 237 | } |
| 238 | port, err := c.MappedPort(ctx, "1521/tcp") |
| 239 | if err != nil { |
| 240 | return nil, err |
| 241 | } |
| 242 | |
| 243 | // Oracle connection string format: oracle://username:password@host:port/service_name |
| 244 | // Use SYSTEM account for privileged operations (like creating users), similar to MySQL root |
| 245 | dsn := fmt.Sprintf("oracle://system:test123@%s:%s/FREEPDB1", host, port.Port()) |
| 246 | db, err := sql.Open("oracle", dsn) |
| 247 | if err != nil { |
| 248 | return nil, err |
| 249 | } |
| 250 | defer func() { |
| 251 | if retErr != nil { |
| 252 | db.Close() |
| 253 | } |
| 254 | }() |
| 255 | |
| 256 | if err := waitDBPing(ctx, db); err != nil { |
| 257 | return nil, err |
| 258 | } |
| 259 | |
| 260 | return &Container{ |
| 261 | container: c, |
| 262 | host: host, |
| 263 | port: port.Port(), |
| 264 | db: db, |
| 265 | }, nil |
| 266 | } |
| 267 |
no test coverage detected