()
| 20 | } |
| 21 | |
| 22 | async start() { |
| 23 | if (this.sequelize) { |
| 24 | console.log("Database already initialized"); |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | const reusableConnectionDetails = this.getReusableConnectionDetails(); |
| 29 | if (reusableConnectionDetails) { |
| 30 | await this.connect(reusableConnectionDetails); |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | const dbDialect = process.env.CB_DB_DIALECT_DEV || "mysql"; |
| 35 | if (dbDialect !== "mysql" && dbDialect !== "postgres") { |
| 36 | throw new Error(`Unsupported test database dialect: ${dbDialect}`); |
| 37 | } |
| 38 | |
| 39 | if (dbDialect === "postgres") { |
| 40 | process.env.PGSSLMODE = "disable"; |
| 41 | process.env.PGSSL = "false"; |
| 42 | process.env.PGSSLROOTCERT = ""; |
| 43 | process.env.PGSSLCERT = ""; |
| 44 | process.env.PGSSLKEY = ""; |
| 45 | console.log("🔧 Set PostgreSQL SSL environment variables to disable SSL"); |
| 46 | } |
| 47 | |
| 48 | try { |
| 49 | const testcontainers = await import("testcontainers"); |
| 50 | GenericContainer = testcontainers.GenericContainer; |
| 51 | Wait = testcontainers.Wait; |
| 52 | console.log("✅ Testcontainers loaded successfully"); |
| 53 | } catch (error) { |
| 54 | throw new Error(`Testcontainers is required for server tests: ${error.message}`); |
| 55 | } |
| 56 | |
| 57 | try { |
| 58 | console.log("🐳 Starting test database container..."); |
| 59 | |
| 60 | if (dbDialect === "postgres") { |
| 61 | await this.startPostgres(); |
| 62 | } else { |
| 63 | await this.startMySQL(); |
| 64 | } |
| 65 | |
| 66 | console.log(`✅ Database container started on port ${this.port}`); |
| 67 | this.setTestEnvVars(); |
| 68 | } catch (error) { |
| 69 | throw new Error(`Failed to start test database container: ${error.message}`); |
| 70 | } |
| 71 | |
| 72 | await this.initializeDatabase(); |
| 73 | } |
| 74 | |
| 75 | async connect(connectionDetails) { |
| 76 | if (this.sequelize) { |
no test coverage detected