@@ -518,6 +518,34 @@ describe("GenericContainer", { timeout: 180_000 }, () => {
518518 expect ( await getRunningContainerNames ( ) ) . not . toContain ( container . getName ( ) ) ;
519519 } ) ;
520520
521+ it ( "should stop but not remove the container" , async ( ) => {
522+ const container = await new GenericContainer ( "cristianrgreco/testcontainer:1.1.14" )
523+ . withName ( `container-${ new RandomUuid ( ) . nextUuid ( ) } ` )
524+ . withAutoRemove ( false )
525+ . start ( ) ;
526+
527+ const stopped = await container . stop ( ) ;
528+ const dockerode = ( await getContainerRuntimeClient ( ) ) . container . dockerode ;
529+ expect ( stopped . getId ( ) ) . toBeTruthy ( ) ;
530+ const lowerLevelContainer = dockerode . getContainer ( stopped . getId ( ) ) ;
531+ expect ( ( await lowerLevelContainer . inspect ( ) ) . State . Status ) . toEqual ( "exited" ) ;
532+ } ) ;
533+
534+ it ( "should stop and override .withAutoRemove" , async ( ) => {
535+ const container = await new GenericContainer ( "cristianrgreco/testcontainer:1.1.14" )
536+ . withName ( `container-${ new RandomUuid ( ) . nextUuid ( ) } ` )
537+ . withAutoRemove ( false )
538+ . start ( ) ;
539+
540+ await container . stop ( { remove : true } ) ;
541+
542+ const stopped = await container . stop ( ) ;
543+ const dockerode = ( await getContainerRuntimeClient ( ) ) . container . dockerode ;
544+ expect ( stopped . getId ( ) ) . toBeTruthy ( ) ;
545+ const lowerLevelContainer = dockerode . getContainer ( stopped . getId ( ) ) ;
546+ await expect ( lowerLevelContainer . inspect ( ) ) . rejects . toThrow ( / 4 0 4 / ) ; // Error: (HTTP code 404) no such container
547+ } ) ;
548+
521549 it ( "should build a target stage" , async ( ) => {
522550 const context = path . resolve ( fixtures , "docker-multi-stage" ) ;
523551 const firstContainer = await GenericContainer . fromDockerfile ( context ) . withTarget ( "first" ) . build ( ) ;
0 commit comments