import { GenericContainer } from "../../generic-container/generic-container" ; import { StartedTestContainer } from "../../test-container" ; import { RandomUuid } from "../../uuid" ; import { AbstractStartedContainer } from "../abstract-started-container" ; import { Port } from "../../port" ; export class PostgreSqlContainer extends GenericContainer { private database = "test" ; private username = new RandomUuid ( ) . nextUuid ( ) ; private password = new RandomUuid ( ) . nextUuid ( ) ; constructor ( image = "postgres:13.3-alpine" ) { super ( image ) ; } public withDatabase ( database ) { this . database = database ; return this ; } public withUsername ( username ) { this . username = username ; return this ; } public withPassword ( password ) { this . password = password ; return this ; } public async start ( ) { this . withExposedPorts ( 5432 ) . withEnv ( "POSTGRES_DB" , this . database ) . withEnv ( "POSTGRES_USER" , this . username ) . withEnv ( "POSTGRES_PASSWORD" , this . password ) . withStartupTimeout ( 120000 ) ; return new StartedPostgreSqlContainer ( await super . start ( ) , this . database , this . username , this . password ) ; } } export class StartedPostgreSqlContainer extends AbstractStartedContainer { private readonly port : Port ; constructor ( startedTestContainer , private readonly database , private readonly username , private readonly password ) { super ( startedTestContainer ) ; this . port = startedTestContainer . getMappedPort ( 5432 ) ; } public getPort ( ) { return this . port ; } public getDatabase ( ) { return this . database ; } public getUsername ( ) { return this . username ; } public getPassword ( ) { return this . password ; } }