import { StartedTestContainer , StopOptions , StoppedTestContainer } from "../test-container" ; import Dockerode from "dockerode" ; import { Command , ContainerName , ExecResult , Host , Id as ContainerId } from "../docker/types" ; import { InspectResult } from "../docker/functions/container/inspect-container" ; import { BoundPorts } from "../bound-ports" ; import { log } from "../logger" ; import { removeContainer } from "../docker/functions/container/remove-container" ; import { Port } from "../port" ; import { execContainer } from "../docker/functions/container/exec-container" ; import { Readable } from "stream" ; import { containerLogs } from "../docker/functions/container/container-logs" ; import { StoppedGenericContainer } from "./stopped-generic-container" ; import { stopContainer } from "../docker/functions/container/stop-container" ; export class StartedGenericContainer implements StartedTestContainer { constructor ( private readonly container , private readonly host , private readonly inspectResult , private readonly boundPorts , private readonly name ) { } public async stop ( options = { } ) { return this . stopContainer ( options ) ; } private async stopContainer ( options = { } ) { log . info ( `Stopping container with ID: ${ this . container . id }` ) ; const resolvedOptions = { timeout : 0 , removeVolumes : true , ... options } ; await stopContainer ( this . container , { timeout : resolvedOptions . timeout } ) ; await removeContainer ( this . container , { removeVolumes : resolvedOptions . removeVolumes } ) ; return new StoppedGenericContainer ( ) ; } public getHost ( ) { return this . host ; } public getMappedPort ( port ) { return this . boundPorts . getBinding ( port ) ; } public getId ( ) { return this . container . id ; } public getName ( ) { return this . name ; } public getNetworkNames ( ) { return Object . keys ( this . inspectResult . networkSettings ) ; } public getNetworkId ( networkName ) { return this . inspectResult . networkSettings [ networkName ] . networkId ; } public getIpAddress ( networkName ) { return this . inspectResult . networkSettings [ networkName ] . ipAddress ; } public exec ( command ) { return execContainer ( this . container , command ) ; } public logs ( ) { return containerLogs ( this . container ) ; } }