2014-07-17 08:29:52 +00:00
package main
import (
2023-07-14 18:02:38 +00:00
"context"
2015-01-23 12:17:05 +00:00
"fmt"
2015-11-09 14:37:24 +00:00
"sort"
2014-07-17 08:29:52 +00:00
"strings"
2019-09-09 21:06:12 +00:00
"testing"
2014-09-12 07:45:50 +00:00
"time"
2015-04-18 16:46:47 +00:00
2017-03-27 15:12:48 +00:00
"github.com/docker/docker/integration-cli/cli"
2017-03-23 17:35:22 +00:00
"github.com/docker/docker/integration-cli/cli/build"
2015-08-20 07:57:15 +00:00
"github.com/docker/docker/pkg/stringid"
2023-10-04 12:10:15 +00:00
"github.com/docker/go-units"
2020-02-07 13:39:24 +00:00
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/icmd"
"gotest.tools/v3/skip"
2014-07-17 08:29:52 +00:00
)
2022-06-16 21:32:10 +00:00
type DockerCLIPsSuite struct {
ds * DockerSuite
}
2023-07-14 18:02:38 +00:00
func ( s * DockerCLIPsSuite ) TearDownTest ( ctx context . Context , c * testing . T ) {
s . ds . TearDownTest ( ctx , c )
2022-06-16 21:32:10 +00:00
}
func ( s * DockerCLIPsSuite ) OnTimeout ( c * testing . T ) {
s . ds . OnTimeout ( c )
}
func ( s * DockerCLIPsSuite ) TestPsListContainersBase ( c * testing . T ) {
2017-09-08 15:16:15 +00:00
existingContainers := ExistingContainerIDs ( c )
2023-07-27 10:53:23 +00:00
firstID := runSleepingContainer ( c , "-d" )
secondID := runSleepingContainer ( c , "-d" )
2014-07-17 08:29:52 +00:00
// not long running
2023-07-27 10:53:23 +00:00
out := cli . DockerCmd ( c , "run" , "-d" , "busybox" , "true" ) . Stdout ( )
2015-04-06 13:21:18 +00:00
thirdID := strings . TrimSpace ( out )
2014-07-17 08:29:52 +00:00
2023-07-27 10:53:23 +00:00
fourthID := runSleepingContainer ( c , "-d" )
2014-07-17 08:29:52 +00:00
2015-04-08 23:20:42 +00:00
// make sure the second is running
2023-07-27 10:53:23 +00:00
cli . WaitRun ( c , secondID )
2015-04-08 23:20:42 +00:00
2014-07-17 08:29:52 +00:00
// make sure third one is not running
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "wait" , thirdID )
2014-07-17 08:29:52 +00:00
2015-04-08 23:20:42 +00:00
// make sure the forth is running
2023-07-27 10:53:23 +00:00
cli . WaitRun ( c , fourthID )
2015-04-08 23:20:42 +00:00
2014-07-17 08:29:52 +00:00
// all
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-a" ) . Stdout ( )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , [ ] string { fourthID , thirdID , secondID , firstID } ) , true , fmt . Sprintf ( "ALL: Container list is not in the correct order: \n%s" , out ) )
2014-07-17 08:29:52 +00:00
// running
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" ) . Stdout ( )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , [ ] string { fourthID , secondID , firstID } ) , true , fmt . Sprintf ( "RUNNING: Container list is not in the correct order: \n%s" , out ) )
2014-07-17 08:29:52 +00:00
// limit
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-n=2" , "-a" ) . Stdout ( )
2014-07-17 08:29:52 +00:00
expected := [ ] string { fourthID , thirdID }
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "LIMIT & ALL: Container list is not in the correct order: \n%s" , out ) )
2014-07-17 08:29:52 +00:00
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-n=2" ) . Stdout ( )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "LIMIT: Container list is not in the correct order: \n%s" , out ) )
2014-07-17 08:29:52 +00:00
2015-11-05 07:08:00 +00:00
// filter since
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-f" , "since=" + firstID , "-a" ) . Stdout ( )
2014-07-17 08:29:52 +00:00
expected = [ ] string { fourthID , thirdID , secondID }
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "SINCE filter & ALL: Container list is not in the correct order: \n%s" , out ) )
2014-07-17 08:29:52 +00:00
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-f" , "since=" + firstID ) . Stdout ( )
2016-02-09 08:06:29 +00:00
expected = [ ] string { fourthID , secondID }
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "SINCE filter: Container list is not in the correct order: \n%s" , out ) )
2014-07-17 08:29:52 +00:00
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-f" , "since=" + thirdID ) . Stdout ( )
2016-02-19 06:07:16 +00:00
expected = [ ] string { fourthID }
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "SINCE filter: Container list is not in the correct order: \n%s" , out ) )
2016-02-19 06:07:16 +00:00
2015-11-05 07:08:00 +00:00
// filter before
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-f" , "before=" + fourthID , "-a" ) . Stdout ( )
2016-02-09 08:06:29 +00:00
expected = [ ] string { thirdID , secondID , firstID }
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "BEFORE filter & ALL: Container list is not in the correct order: \n%s" , out ) )
2014-07-17 08:29:52 +00:00
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-f" , "before=" + fourthID ) . Stdout ( )
2016-02-09 08:06:29 +00:00
expected = [ ] string { secondID , firstID }
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "BEFORE filter: Container list is not in the correct order: \n%s" , out ) )
2014-07-17 08:29:52 +00:00
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-f" , "before=" + thirdID ) . Stdout ( )
2016-02-19 06:07:16 +00:00
expected = [ ] string { secondID , firstID }
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "SINCE filter: Container list is not in the correct order: \n%s" , out ) )
2016-02-19 06:07:16 +00:00
2015-11-05 07:08:00 +00:00
// filter since & before
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-f" , "since=" + firstID , "-f" , "before=" + fourthID , "-a" ) . Stdout ( )
2014-07-17 08:29:52 +00:00
expected = [ ] string { thirdID , secondID }
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "SINCE filter, BEFORE filter & ALL: Container list is not in the correct order: \n%s" , out ) )
2014-07-17 08:29:52 +00:00
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-f" , "since=" + firstID , "-f" , "before=" + fourthID ) . Stdout ( )
2016-02-09 08:06:29 +00:00
expected = [ ] string { secondID }
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "SINCE filter, BEFORE filter: Container list is not in the correct order: \n%s" , out ) )
2014-07-17 08:29:52 +00:00
2015-11-05 07:08:00 +00:00
// filter since & limit
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-f" , "since=" + firstID , "-n=2" , "-a" ) . Stdout ( )
2014-07-17 08:29:52 +00:00
expected = [ ] string { fourthID , thirdID }
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "SINCE filter, LIMIT & ALL: Container list is not in the correct order: \n%s" , out ) )
2014-07-17 08:29:52 +00:00
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-f" , "since=" + firstID , "-n=2" ) . Stdout ( )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "SINCE filter, LIMIT: Container list is not in the correct order: \n%s" , out ) )
2014-07-17 08:29:52 +00:00
2015-11-05 07:08:00 +00:00
// filter before & limit
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-f" , "before=" + fourthID , "-n=1" , "-a" ) . Stdout ( )
2014-07-17 08:29:52 +00:00
expected = [ ] string { thirdID }
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s" , out ) )
2014-07-17 08:29:52 +00:00
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-f" , "before=" + fourthID , "-n=1" ) . Stdout ( )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "BEFORE filter, LIMIT: Container list is not in the correct order: \n%s" , out ) )
2014-07-17 08:29:52 +00:00
2015-11-05 07:08:00 +00:00
// filter since & filter before & limit
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-f" , "since=" + firstID , "-f" , "before=" + fourthID , "-n=1" , "-a" ) . Stdout ( )
2014-07-17 08:29:52 +00:00
expected = [ ] string { thirdID }
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "SINCE filter, BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s" , out ) )
2014-07-17 08:29:52 +00:00
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-f" , "since=" + firstID , "-f" , "before=" + fourthID , "-n=1" ) . Stdout ( )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , assertContainerList ( RemoveOutputForExistingElements ( out , existingContainers ) , expected ) , true , fmt . Sprintf ( "SINCE filter, BEFORE filter, LIMIT: Container list is not in the correct order: \n%s" , out ) )
2016-02-09 08:06:29 +00:00
}
2014-07-17 08:29:52 +00:00
func assertContainerList ( out string , expected [ ] string ) bool {
lines := strings . Split ( strings . Trim ( out , "\n " ) , "\n" )
2016-02-09 08:06:29 +00:00
2014-07-17 08:29:52 +00:00
if len ( lines ) - 1 != len ( expected ) {
return false
}
2014-10-06 14:26:55 +00:00
containerIDIndex := strings . Index ( lines [ 0 ] , "CONTAINER ID" )
2014-07-17 08:29:52 +00:00
for i := 0 ; i < len ( expected ) ; i ++ {
2014-10-06 14:26:55 +00:00
foundID := lines [ i + 1 ] [ containerIDIndex : containerIDIndex + 12 ]
2014-07-17 08:29:52 +00:00
if foundID != expected [ i ] [ : 12 ] {
return false
}
}
return true
}
2014-09-12 07:45:50 +00:00
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsListContainersSize ( c * testing . T ) {
2016-01-23 04:44:46 +00:00
// Problematic on Windows as it doesn't report the size correctly @swernli
2015-08-28 17:36:42 +00:00
testRequires ( c , DaemonIsLinux )
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "run" , "-d" , "busybox" )
2015-05-19 18:33:59 +00:00
2023-07-27 10:53:23 +00:00
baseOut := cli . DockerCmd ( c , "ps" , "-s" , "-n=1" ) . Stdout ( )
2015-03-26 01:40:23 +00:00
baseLines := strings . Split ( strings . Trim ( baseOut , "\n " ) , "\n" )
baseSizeIndex := strings . Index ( baseLines [ 0 ] , "SIZE" )
2023-10-04 12:10:15 +00:00
baseFoundsize , _ , _ := strings . Cut ( baseLines [ 1 ] [ baseSizeIndex : ] , " " )
baseBytes , err := units . FromHumanSize ( baseFoundsize )
2019-04-04 13:23:19 +00:00
assert . NilError ( c , err )
2015-01-23 12:17:05 +00:00
2023-07-27 10:53:23 +00:00
const name = "test_size"
cli . DockerCmd ( c , "run" , "--name" , name , "busybox" , "sh" , "-c" , "echo 1 > test" )
2017-01-16 10:30:14 +00:00
id := getIDByName ( c , name )
2014-09-12 07:45:50 +00:00
2017-01-16 15:39:12 +00:00
var result * icmd . Result
2015-05-19 18:33:59 +00:00
2014-09-12 07:45:50 +00:00
wait := make ( chan struct { } )
go func ( ) {
2017-01-16 15:39:12 +00:00
result = icmd . RunCommand ( dockerBinary , "ps" , "-s" , "-n=1" )
2014-09-12 07:45:50 +00:00
close ( wait )
} ( )
select {
case <- wait :
case <- time . After ( 3 * time . Second ) :
2023-07-05 10:12:16 +00:00
c . Fatalf ( ` Calling "docker ps -s" timed out! ` )
2014-09-12 07:45:50 +00:00
}
2017-01-16 15:39:12 +00:00
result . Assert ( c , icmd . Success )
lines := strings . Split ( strings . Trim ( result . Combined ( ) , "\n " ) , "\n" )
2019-04-04 13:23:19 +00:00
assert . Equal ( c , len ( lines ) , 2 , "Expected 2 lines for 'ps -s -n=1' output, got %d" , len ( lines ) )
2014-09-12 07:45:50 +00:00
sizeIndex := strings . Index ( lines [ 0 ] , "SIZE" )
idIndex := strings . Index ( lines [ 0 ] , "CONTAINER ID" )
foundID := lines [ 1 ] [ idIndex : idIndex + 12 ]
2019-09-09 21:08:22 +00:00
assert . Equal ( c , foundID , id [ : 12 ] , fmt . Sprintf ( "Expected id %s, got %s" , id [ : 12 ] , foundID ) )
2023-10-04 12:28:00 +00:00
foundSize , _ , _ := strings . Cut ( strings . TrimSpace ( lines [ 1 ] [ sizeIndex : ] ) , " " )
// With snapshotters the reported usage is the real space occupied on the
// filesystem (also includes metadata), so this new file can actually
// result in a bigger increase depending on the underlying filesystem (on
// ext4 this would be 4096 which is a minimum allocation unit).
if testEnv . UsingSnapshotter ( ) {
newBytes , err := units . FromHumanSize ( foundSize )
assert . NilError ( c , err )
// Check if size increased by at least 2 bytes.
assert . Check ( c , newBytes >= baseBytes + 2 )
} else {
expectedSize := units . HumanSize ( float64 ( baseBytes + 2 ) )
assert . Assert ( c , strings . Contains ( foundSize , expectedSize ) , "Expected size %q, got %q" , expectedSize , foundSize )
}
2014-09-26 23:25:50 +00:00
}
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsListContainersFilterStatus ( c * testing . T ) {
2017-09-08 15:16:15 +00:00
existingContainers := ExistingContainerIDs ( c )
2014-09-26 23:25:50 +00:00
// start exited container
2017-03-27 15:12:48 +00:00
out := cli . DockerCmd ( c , "run" , "-d" , "busybox" ) . Combined ( )
2015-04-06 13:21:18 +00:00
firstID := strings . TrimSpace ( out )
2014-09-26 23:25:50 +00:00
2015-11-11 17:51:36 +00:00
// make sure the exited container is not running
2017-03-27 15:12:48 +00:00
cli . DockerCmd ( c , "wait" , firstID )
2014-09-26 23:25:50 +00:00
// start running container
2017-03-27 15:12:48 +00:00
out = cli . DockerCmd ( c , "run" , "-itd" , "busybox" ) . Combined ( )
2015-04-06 13:21:18 +00:00
secondID := strings . TrimSpace ( out )
2014-09-26 23:25:50 +00:00
// filter containers by exited
2017-03-27 15:12:48 +00:00
out = cli . DockerCmd ( c , "ps" , "--no-trunc" , "-q" , "--filter=status=exited" ) . Combined ( )
2014-09-26 23:25:50 +00:00
containerOut := strings . TrimSpace ( out )
2019-09-09 21:05:56 +00:00
assert . Equal ( c , RemoveOutputForExistingElements ( containerOut , existingContainers ) , firstID )
2014-09-26 23:25:50 +00:00
2017-03-27 15:12:48 +00:00
out = cli . DockerCmd ( c , "ps" , "-a" , "--no-trunc" , "-q" , "--filter=status=running" ) . Combined ( )
2014-09-26 23:25:50 +00:00
containerOut = strings . TrimSpace ( out )
2019-09-09 21:05:56 +00:00
assert . Equal ( c , RemoveOutputForExistingElements ( containerOut , existingContainers ) , secondID )
2014-09-26 23:25:50 +00:00
2017-03-27 15:12:48 +00:00
result := cli . Docker ( cli . Args ( "ps" , "-a" , "-q" , "--filter=status=rubbish" ) , cli . WithTimeout ( time . Second * 60 ) )
2017-08-23 21:01:29 +00:00
result . Assert ( c , icmd . Expected {
2016-08-04 16:57:34 +00:00
ExitCode : 1 ,
2023-12-04 22:26:00 +00:00
Err : "invalid filter 'status=rubbish'" ,
2016-08-04 16:57:34 +00:00
} )
2016-01-23 04:44:46 +00:00
// Windows doesn't support pausing of containers
2023-06-14 09:46:00 +00:00
if testEnv . DaemonInfo . OSType != "windows" {
2016-01-23 04:44:46 +00:00
// pause running container
2017-03-27 15:12:48 +00:00
out = cli . DockerCmd ( c , "run" , "-itd" , "busybox" ) . Combined ( )
2016-01-23 04:44:46 +00:00
pausedID := strings . TrimSpace ( out )
2017-03-27 15:12:48 +00:00
cli . DockerCmd ( c , "pause" , pausedID )
2016-01-23 04:44:46 +00:00
// make sure the container is unpaused to let the daemon stop it properly
2017-03-27 15:12:48 +00:00
defer func ( ) { cli . DockerCmd ( c , "unpause" , pausedID ) } ( )
2016-01-23 04:44:46 +00:00
2017-03-27 15:12:48 +00:00
out = cli . DockerCmd ( c , "ps" , "--no-trunc" , "-q" , "--filter=status=paused" ) . Combined ( )
2016-01-23 04:44:46 +00:00
containerOut = strings . TrimSpace ( out )
2019-09-09 21:05:56 +00:00
assert . Equal ( c , RemoveOutputForExistingElements ( containerOut , existingContainers ) , pausedID )
2016-01-23 04:44:46 +00:00
}
2014-09-12 07:45:50 +00:00
}
2014-10-13 06:12:44 +00:00
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsListContainersFilterHealth ( c * testing . T ) {
2020-09-21 19:21:22 +00:00
skip . If ( c , RuntimeIsWindowsContainerd ( ) , "FIXME. Hang on Windows + containerd combination" )
2017-09-15 13:16:38 +00:00
existingContainers := ExistingContainerIDs ( c )
2016-07-15 18:21:19 +00:00
// Test legacy no health check
2023-07-27 10:53:23 +00:00
containerID := runSleepingContainer ( c , "--name=none_legacy" )
2016-07-15 18:21:19 +00:00
2017-04-11 19:18:30 +00:00
cli . WaitRun ( c , containerID )
2016-07-15 18:21:19 +00:00
2023-07-27 10:53:23 +00:00
out := cli . DockerCmd ( c , "ps" , "-q" , "-l" , "--no-trunc" , "--filter=health=none" ) . Combined ( )
2016-07-15 18:21:19 +00:00
containerOut := strings . TrimSpace ( out )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , containerOut , containerID , fmt . Sprintf ( "Expected id %s, got %s for legacy none filter, output: %q" , containerID , containerOut , out ) )
2016-07-15 18:21:19 +00:00
// Test no health check specified explicitly
2023-07-27 10:53:23 +00:00
containerID = runSleepingContainer ( c , "--name=none" , "--no-healthcheck" )
2016-07-15 18:21:19 +00:00
2017-04-11 19:18:30 +00:00
cli . WaitRun ( c , containerID )
2016-07-15 18:21:19 +00:00
2017-04-11 19:18:30 +00:00
out = cli . DockerCmd ( c , "ps" , "-q" , "-l" , "--no-trunc" , "--filter=health=none" ) . Combined ( )
2016-07-15 18:21:19 +00:00
containerOut = strings . TrimSpace ( out )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , containerOut , containerID , fmt . Sprintf ( "Expected id %s, got %s for none filter, output: %q" , containerID , containerOut , out ) )
2016-07-15 18:21:19 +00:00
// Test failing health check
2017-04-16 21:39:30 +00:00
out = runSleepingContainer ( c , "--name=failing_container" , "--health-cmd=exit 1" , "--health-interval=1s" )
2016-07-15 18:21:19 +00:00
containerID = strings . TrimSpace ( out )
waitForHealthStatus ( c , "failing_container" , "starting" , "unhealthy" )
2017-04-11 19:18:30 +00:00
out = cli . DockerCmd ( c , "ps" , "-q" , "--no-trunc" , "--filter=health=unhealthy" ) . Combined ( )
2016-07-15 18:21:19 +00:00
containerOut = strings . TrimSpace ( out )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , containerOut , containerID , fmt . Sprintf ( "Expected containerID %s, got %s for unhealthy filter, output: %q" , containerID , containerOut , out ) )
2016-07-15 18:21:19 +00:00
// Check passing healthcheck
2023-07-27 10:53:23 +00:00
containerID = runSleepingContainer ( c , "--name=passing_container" , "--health-cmd=exit 0" , "--health-interval=1s" )
2016-07-15 18:21:19 +00:00
waitForHealthStatus ( c , "passing_container" , "starting" , "healthy" )
2017-04-11 19:18:30 +00:00
out = cli . DockerCmd ( c , "ps" , "-q" , "--no-trunc" , "--filter=health=healthy" ) . Combined ( )
2017-09-15 13:16:38 +00:00
containerOut = strings . TrimSpace ( RemoveOutputForExistingElements ( out , existingContainers ) )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , containerOut , containerID , fmt . Sprintf ( "Expected containerID %s, got %s for healthy filter, output: %q" , containerID , containerOut , out ) )
2016-07-15 18:21:19 +00:00
}
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsListContainersFilterID ( c * testing . T ) {
2014-10-13 06:12:44 +00:00
// start container
2023-07-27 10:53:23 +00:00
out := cli . DockerCmd ( c , "run" , "-d" , "busybox" ) . Stdout ( )
2015-04-06 13:21:18 +00:00
firstID := strings . TrimSpace ( out )
2014-10-13 06:12:44 +00:00
// start another container
2016-01-27 04:16:36 +00:00
runSleepingContainer ( c )
2014-10-13 06:12:44 +00:00
// filter containers by id
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-a" , "-q" , "--filter=id=" + firstID ) . Stdout ( )
2014-10-13 06:12:44 +00:00
containerOut := strings . TrimSpace ( out )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , containerOut , firstID [ : 12 ] , fmt . Sprintf ( "Expected id %s, got %s for exited filter, output: %q" , firstID [ : 12 ] , containerOut , out ) )
2014-10-13 06:12:44 +00:00
}
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsListContainersFilterName ( c * testing . T ) {
2014-10-13 06:12:44 +00:00
// start container
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "run" , "--name=a_name_to_match" , "busybox" )
2017-01-16 10:30:14 +00:00
id := getIDByName ( c , "a_name_to_match" )
2014-10-13 06:12:44 +00:00
// start another container
2016-01-27 04:16:36 +00:00
runSleepingContainer ( c , "--name=b_name_to_match" )
2014-10-13 06:12:44 +00:00
// filter containers by name
2023-07-27 10:53:23 +00:00
out := cli . DockerCmd ( c , "ps" , "-a" , "-q" , "--filter=name=a_name_to_match" ) . Stdout ( )
2014-10-13 06:12:44 +00:00
containerOut := strings . TrimSpace ( out )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , containerOut , id [ : 12 ] , fmt . Sprintf ( "Expected id %s, got %s for exited filter, output: %q" , id [ : 12 ] , containerOut , out ) )
2014-10-13 06:12:44 +00:00
}
2014-11-03 18:50:16 +00:00
2015-08-20 07:57:15 +00:00
// Test for the ancestor filter for ps.
// There is also the same test but with image:tag@digest in docker_cli_by_digest_test.go
//
// What the test setups :
// - Create 2 image based on busybox using the same repository but different tags
// - Create an image based on the previous image (images_ps_filter_test2)
// - Run containers for each of those image (busybox, images_ps_filter_test1, images_ps_filter_test2)
// - Filter them out :P
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsListContainersFilterAncestorImage ( c * testing . T ) {
2017-09-08 15:16:15 +00:00
existingContainers := ExistingContainerIDs ( c )
2015-08-20 07:57:15 +00:00
// Build images
imageName1 := "images_ps_filter_test1"
2017-03-23 17:35:22 +00:00
buildImageSuccessfully ( c , imageName1 , build . WithDockerfile ( ` FROM busybox
2017-01-16 10:30:14 +00:00
LABEL match me 1 ` ) )
imageID1 := getIDByName ( c , imageName1 )
2015-08-20 07:57:15 +00:00
imageName1Tagged := "images_ps_filter_test1:tag"
2017-03-23 17:35:22 +00:00
buildImageSuccessfully ( c , imageName1Tagged , build . WithDockerfile ( ` FROM busybox
2017-01-16 10:30:14 +00:00
LABEL match me 1 tagged ` ) )
imageID1Tagged := getIDByName ( c , imageName1Tagged )
2015-08-20 07:57:15 +00:00
imageName2 := "images_ps_filter_test2"
2017-03-23 17:35:22 +00:00
buildImageSuccessfully ( c , imageName2 , build . WithDockerfile ( fmt . Sprintf ( ` FROM % s
2017-01-16 10:30:14 +00:00
LABEL match me 2 ` , imageName1 ) ) )
imageID2 := getIDByName ( c , imageName2 )
2015-08-20 07:57:15 +00:00
// start containers
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "run" , "--name=first" , "busybox" , "echo" , "hello" )
2017-01-16 10:30:14 +00:00
firstID := getIDByName ( c , "first" )
2015-08-20 07:57:15 +00:00
// start another container
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "run" , "--name=second" , "busybox" , "echo" , "hello" )
2017-01-16 10:30:14 +00:00
secondID := getIDByName ( c , "second" )
2015-08-20 07:57:15 +00:00
// start third container
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "run" , "--name=third" , imageName1 , "echo" , "hello" )
2017-01-16 10:30:14 +00:00
thirdID := getIDByName ( c , "third" )
2015-08-20 07:57:15 +00:00
// start fourth container
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "run" , "--name=fourth" , imageName1Tagged , "echo" , "hello" )
2017-01-16 10:30:14 +00:00
fourthID := getIDByName ( c , "fourth" )
2015-08-20 07:57:15 +00:00
// start fifth container
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "run" , "--name=fifth" , imageName2 , "echo" , "hello" )
2017-01-16 10:30:14 +00:00
fifthID := getIDByName ( c , "fifth" )
2015-08-20 07:57:15 +00:00
2022-01-20 12:43:42 +00:00
filterTestSuite := [ ] struct {
2015-08-20 07:57:15 +00:00
filterName string
expectedIDs [ ] string
} {
// non existent stuff
{ "nonexistent" , [ ] string { } } ,
{ "nonexistent:tag" , [ ] string { } } ,
// image
{ "busybox" , [ ] string { firstID , secondID , thirdID , fourthID , fifthID } } ,
{ imageName1 , [ ] string { thirdID , fifthID } } ,
{ imageName2 , [ ] string { fifthID } } ,
// image:tag
{ fmt . Sprintf ( "%s:latest" , imageName1 ) , [ ] string { thirdID , fifthID } } ,
{ imageName1Tagged , [ ] string { fourthID } } ,
// short-id
{ stringid . TruncateID ( imageID1 ) , [ ] string { thirdID , fifthID } } ,
{ stringid . TruncateID ( imageID2 ) , [ ] string { fifthID } } ,
// full-id
{ imageID1 , [ ] string { thirdID , fifthID } } ,
{ imageID1Tagged , [ ] string { fourthID } } ,
{ imageID2 , [ ] string { fifthID } } ,
}
2016-02-28 10:47:37 +00:00
var out string
2015-08-20 07:57:15 +00:00
for _ , filter := range filterTestSuite {
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-a" , "-q" , "--no-trunc" , "--filter=ancestor=" + filter . filterName ) . Stdout ( )
2017-09-08 15:16:15 +00:00
checkPsAncestorFilterOutput ( c , RemoveOutputForExistingElements ( out , existingContainers ) , filter . filterName , filter . expectedIDs )
2015-08-20 07:57:15 +00:00
}
// Multiple ancestor filter
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-a" , "-q" , "--no-trunc" , "--filter=ancestor=" + imageName2 , "--filter=ancestor=" + imageName1Tagged ) . Stdout ( )
2017-09-08 15:16:15 +00:00
checkPsAncestorFilterOutput ( c , RemoveOutputForExistingElements ( out , existingContainers ) , imageName2 + "," + imageName1Tagged , [ ] string { fourthID , fifthID } )
2015-08-20 07:57:15 +00:00
}
2019-09-09 21:05:55 +00:00
func checkPsAncestorFilterOutput ( c * testing . T , out string , filterName string , expectedIDs [ ] string ) {
2018-05-19 11:38:54 +00:00
var actualIDs [ ] string
2015-08-20 07:57:15 +00:00
if out != "" {
actualIDs = strings . Split ( out [ : len ( out ) - 1 ] , "\n" )
}
sort . Strings ( actualIDs )
sort . Strings ( expectedIDs )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , len ( actualIDs ) , len ( expectedIDs ) , fmt . Sprintf ( "Expected filtered container(s) for %s ancestor filter to be %v:%v, got %v:%v" , filterName , len ( expectedIDs ) , expectedIDs , len ( actualIDs ) , actualIDs ) )
2015-08-20 07:57:15 +00:00
if len ( expectedIDs ) > 0 {
same := true
for i := range expectedIDs {
if actualIDs [ i ] != expectedIDs [ i ] {
c . Logf ( "%s, %s" , actualIDs [ i ] , expectedIDs [ i ] )
same = false
break
}
}
2019-09-09 21:08:22 +00:00
assert . Equal ( c , same , true , fmt . Sprintf ( "Expected filtered container(s) for %s ancestor filter to be %v, got %v" , filterName , expectedIDs , actualIDs ) )
2015-08-20 07:57:15 +00:00
}
}
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsListContainersFilterLabel ( c * testing . T ) {
2015-01-07 00:04:10 +00:00
// start container
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "run" , "--name=first" , "-l" , "match=me" , "-l" , "second=tag" , "busybox" )
2017-01-16 10:30:14 +00:00
firstID := getIDByName ( c , "first" )
2015-01-07 00:04:10 +00:00
// start another container
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "run" , "--name=second" , "-l" , "match=me too" , "busybox" )
2017-01-16 10:30:14 +00:00
secondID := getIDByName ( c , "second" )
2015-01-07 00:04:10 +00:00
// start third container
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "run" , "--name=third" , "-l" , "nomatch=me" , "busybox" )
2017-01-16 10:30:14 +00:00
thirdID := getIDByName ( c , "third" )
2015-01-07 00:04:10 +00:00
// filter containers by exact match
2023-07-27 10:53:23 +00:00
out := cli . DockerCmd ( c , "ps" , "-a" , "-q" , "--no-trunc" , "--filter=label=match=me" ) . Stdout ( )
2015-01-07 00:04:10 +00:00
containerOut := strings . TrimSpace ( out )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , containerOut , firstID , fmt . Sprintf ( "Expected id %s, got %s for exited filter, output: %q" , firstID , containerOut , out ) )
2015-01-07 00:04:10 +00:00
2015-03-09 05:18:59 +00:00
// filter containers by two labels
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-a" , "-q" , "--no-trunc" , "--filter=label=match=me" , "--filter=label=second=tag" ) . Stdout ( )
2015-03-09 05:18:59 +00:00
containerOut = strings . TrimSpace ( out )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , containerOut , firstID , fmt . Sprintf ( "Expected id %s, got %s for exited filter, output: %q" , firstID , containerOut , out ) )
2015-03-09 05:18:59 +00:00
// filter containers by two labels, but expect not found because of AND behavior
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-a" , "-q" , "--no-trunc" , "--filter=label=match=me" , "--filter=label=second=tag-no" ) . Stdout ( )
2015-03-09 05:18:59 +00:00
containerOut = strings . TrimSpace ( out )
2019-09-09 21:08:22 +00:00
assert . Equal ( c , containerOut , "" , fmt . Sprintf ( "Expected nothing, got %s for exited filter, output: %q" , containerOut , out ) )
2015-03-09 05:18:59 +00:00
2015-01-07 00:04:10 +00:00
// filter containers by exact key
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-a" , "-q" , "--no-trunc" , "--filter=label=match" ) . Stdout ( )
2015-01-07 00:04:10 +00:00
containerOut = strings . TrimSpace ( out )
2019-09-09 21:08:22 +00:00
assert . Assert ( c , strings . Contains ( containerOut , firstID ) )
assert . Assert ( c , strings . Contains ( containerOut , secondID ) )
2019-09-09 21:07:46 +00:00
assert . Assert ( c , ! strings . Contains ( containerOut , thirdID ) )
2015-01-07 00:04:10 +00:00
}
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsListContainersFilterExited ( c * testing . T ) {
2019-09-17 22:10:54 +00:00
// TODO Flaky on Windows CI [both RS1 and RS5]
// On slower machines the container may not have exited
// yet when we filter below by exit status/exit value.
skip . If ( c , DaemonIsWindows ( ) , "FLAKY on Windows, see #20819" )
2016-01-27 04:16:36 +00:00
runSleepingContainer ( c , "--name=sleep" )
2015-01-08 22:51:47 +00:00
2023-07-27 10:53:23 +00:00
firstZero := cli . DockerCmd ( c , "run" , "-d" , "busybox" , "true" ) . Stdout ( )
secondZero := cli . DockerCmd ( c , "run" , "-d" , "busybox" , "true" ) . Stdout ( )
2014-11-03 18:50:16 +00:00
2015-10-14 07:03:09 +00:00
out , _ , err := dockerCmdWithError ( "run" , "--name" , "nonzero1" , "busybox" , "false" )
2019-09-11 10:57:29 +00:00
assert . Assert ( c , err != nil , "Should fail. out: %s" , out )
2017-01-16 10:30:14 +00:00
firstNonZero := getIDByName ( c , "nonzero1" )
2014-11-03 18:50:16 +00:00
2015-10-14 07:03:09 +00:00
out , _ , err = dockerCmdWithError ( "run" , "--name" , "nonzero2" , "busybox" , "false" )
2019-09-11 10:57:29 +00:00
assert . Assert ( c , err != nil , "Should fail. out: %s" , out )
2017-01-16 10:30:14 +00:00
secondNonZero := getIDByName ( c , "nonzero2" )
2014-11-03 18:50:16 +00:00
// filter containers by exited=0
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-a" , "-q" , "--no-trunc" , "--filter=exited=0" ) . Stdout ( )
2019-09-09 21:08:22 +00:00
assert . Assert ( c , strings . Contains ( out , strings . TrimSpace ( firstZero ) ) )
assert . Assert ( c , strings . Contains ( out , strings . TrimSpace ( secondZero ) ) )
2019-09-09 21:07:46 +00:00
assert . Assert ( c , ! strings . Contains ( out , strings . TrimSpace ( firstNonZero ) ) )
assert . Assert ( c , ! strings . Contains ( out , strings . TrimSpace ( secondNonZero ) ) )
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-a" , "-q" , "--no-trunc" , "--filter=exited=1" ) . Stdout ( )
2019-09-09 21:08:22 +00:00
assert . Assert ( c , strings . Contains ( out , strings . TrimSpace ( firstNonZero ) ) )
assert . Assert ( c , strings . Contains ( out , strings . TrimSpace ( secondNonZero ) ) )
2019-09-09 21:07:46 +00:00
assert . Assert ( c , ! strings . Contains ( out , strings . TrimSpace ( firstZero ) ) )
assert . Assert ( c , ! strings . Contains ( out , strings . TrimSpace ( secondZero ) ) )
2014-11-03 18:50:16 +00:00
}
2015-02-05 22:55:08 +00:00
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsRightTagName ( c * testing . T ) {
2016-01-23 04:44:46 +00:00
// TODO Investigate further why this fails on Windows to Windows CI
2015-08-28 17:36:42 +00:00
testRequires ( c , DaemonIsLinux )
2017-09-08 15:16:15 +00:00
existingContainers := ExistingContainerNames ( c )
2015-02-05 22:55:08 +00:00
tag := "asybox:shmatest"
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "tag" , "busybox" , tag )
2015-02-05 22:55:08 +00:00
2023-07-27 10:53:23 +00:00
id1 := runSleepingContainer ( c )
id2 := runSleepingContainerInImage ( c , tag )
2015-04-01 14:08:00 +00:00
2023-07-27 10:53:23 +00:00
imageID := inspectField ( c , "busybox" , "Id" )
2015-04-01 14:08:00 +00:00
2023-07-27 10:53:23 +00:00
id3 := runSleepingContainerInImage ( c , imageID )
2015-04-01 14:08:00 +00:00
2023-07-27 10:53:23 +00:00
out := cli . DockerCmd ( c , "ps" , "--no-trunc" ) . Stdout ( )
2019-08-05 15:54:15 +00:00
lines := strings . Split ( strings . TrimSpace ( out ) , "\n" )
2017-09-08 15:16:15 +00:00
lines = RemoveLinesForExistingElements ( lines , existingContainers )
2015-02-05 22:55:08 +00:00
// skip header
lines = lines [ 1 : ]
2019-04-04 13:23:19 +00:00
assert . Equal ( c , len ( lines ) , 3 , "There should be 3 running container, got %d" , len ( lines ) )
2015-02-05 22:55:08 +00:00
for _ , line := range lines {
f := strings . Fields ( line )
switch f [ 0 ] {
case id1 :
2019-09-09 21:08:22 +00:00
assert . Equal ( c , f [ 1 ] , "busybox" , fmt . Sprintf ( "Expected %s tag for id %s, got %s" , "busybox" , id1 , f [ 1 ] ) )
2015-02-05 22:55:08 +00:00
case id2 :
2019-09-09 21:08:22 +00:00
assert . Equal ( c , f [ 1 ] , tag , fmt . Sprintf ( "Expected %s tag for id %s, got %s" , tag , id2 , f [ 1 ] ) )
2015-04-01 14:08:00 +00:00
case id3 :
2019-09-09 21:08:22 +00:00
assert . Equal ( c , f [ 1 ] , imageID , fmt . Sprintf ( "Expected %s imageID for id %s, got %s" , tag , id3 , f [ 1 ] ) )
2015-02-05 22:55:08 +00:00
default :
2015-04-18 16:46:47 +00:00
c . Fatalf ( "Unexpected id %s, expected %s and %s and %s" , f [ 0 ] , id1 , id2 , id3 )
2015-02-05 22:55:08 +00:00
}
}
}
2015-01-15 19:03:46 +00:00
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsListContainersFilterCreated ( c * testing . T ) {
2015-05-20 21:51:58 +00:00
// create a container
2023-07-27 10:53:23 +00:00
out := cli . DockerCmd ( c , "create" , "busybox" ) . Stdout ( )
2015-05-20 21:51:58 +00:00
cID := strings . TrimSpace ( out )
shortCID := cID [ : 12 ]
// Make sure it DOESN'T show up w/o a '-a' for normal 'ps'
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-q" ) . Stdout ( )
2019-09-11 10:57:29 +00:00
assert . Assert ( c , ! strings . Contains ( out , shortCID ) , "Should have not seen '%s' in ps output:\n%s" , shortCID , out )
2015-05-20 21:51:58 +00:00
// Make sure it DOES show up as 'Created' for 'ps -a'
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-a" ) . Stdout ( )
2015-05-20 21:51:58 +00:00
hits := 0
for _ , line := range strings . Split ( out , "\n" ) {
if ! strings . Contains ( line , shortCID ) {
continue
}
hits ++
2019-09-11 10:57:29 +00:00
assert . Assert ( c , strings . Contains ( line , "Created" ) , "Missing 'Created' on '%s'" , line )
2015-05-20 21:51:58 +00:00
}
2019-09-09 21:08:22 +00:00
assert . Equal ( c , hits , 1 , fmt . Sprintf ( "Should have seen '%s' in ps -a output once:%d\n%s" , shortCID , hits , out ) )
2015-05-20 21:51:58 +00:00
// filter containers by 'create' - note, no -a needed
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "-q" , "-f" , "status=created" ) . Stdout ( )
2015-05-20 21:51:58 +00:00
containerOut := strings . TrimSpace ( out )
2022-03-13 12:59:45 +00:00
assert . Assert ( c , strings . Contains ( containerOut , shortCID ) , "Should have seen '%s' in ps output:\n%s" , shortCID , out )
2015-05-20 21:51:58 +00:00
}
2015-07-17 04:03:16 +00:00
2015-05-01 01:13:18 +00:00
// Test for GitHub issue #12595
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsImageIDAfterUpdate ( c * testing . T ) {
2016-01-23 04:44:46 +00:00
// TODO: Investigate why this fails on Windows to Windows CI further.
2015-08-28 17:36:42 +00:00
testRequires ( c , DaemonIsLinux )
2015-05-01 01:13:18 +00:00
originalImageName := "busybox:TestPsImageIDAfterUpdate-original"
updatedImageName := "busybox:TestPsImageIDAfterUpdate-updated"
2017-09-08 15:16:15 +00:00
existingContainers := ExistingContainerIDs ( c )
2017-01-05 11:38:34 +00:00
icmd . RunCommand ( dockerBinary , "tag" , "busybox:latest" , originalImageName ) . Assert ( c , icmd . Success )
2015-05-01 01:13:18 +00:00
2017-01-16 10:30:14 +00:00
originalImageID := getIDByName ( c , originalImageName )
2015-05-01 01:13:18 +00:00
2017-01-05 11:38:34 +00:00
result := icmd . RunCommand ( dockerBinary , append ( [ ] string { "run" , "-d" , originalImageName } , sleepCommandForDaemonPlatform ( ) ... ) ... )
result . Assert ( c , icmd . Success )
containerID := strings . TrimSpace ( result . Combined ( ) )
2015-05-01 01:13:18 +00:00
2017-01-05 11:38:34 +00:00
result = icmd . RunCommand ( dockerBinary , "ps" , "--no-trunc" )
result . Assert ( c , icmd . Success )
2015-05-01 01:13:18 +00:00
2019-08-05 15:54:15 +00:00
lines := strings . Split ( strings . TrimSpace ( result . Combined ( ) ) , "\n" )
2017-09-08 15:16:15 +00:00
lines = RemoveLinesForExistingElements ( lines , existingContainers )
2015-05-01 01:13:18 +00:00
// skip header
lines = lines [ 1 : ]
2019-09-09 21:05:56 +00:00
assert . Equal ( c , len ( lines ) , 1 )
2015-05-01 01:13:18 +00:00
for _ , line := range lines {
f := strings . Fields ( line )
2019-09-09 21:05:56 +00:00
assert . Equal ( c , f [ 1 ] , originalImageName )
2015-05-01 01:13:18 +00:00
}
2017-01-05 11:38:34 +00:00
icmd . RunCommand ( dockerBinary , "commit" , containerID , updatedImageName ) . Assert ( c , icmd . Success )
icmd . RunCommand ( dockerBinary , "tag" , updatedImageName , originalImageName ) . Assert ( c , icmd . Success )
2015-05-01 01:13:18 +00:00
2017-01-05 11:38:34 +00:00
result = icmd . RunCommand ( dockerBinary , "ps" , "--no-trunc" )
result . Assert ( c , icmd . Success )
2015-05-01 01:13:18 +00:00
2019-08-05 15:54:15 +00:00
lines = strings . Split ( strings . TrimSpace ( result . Combined ( ) ) , "\n" )
2017-09-08 15:16:15 +00:00
lines = RemoveLinesForExistingElements ( lines , existingContainers )
2015-05-01 01:13:18 +00:00
// skip header
lines = lines [ 1 : ]
2019-09-09 21:05:56 +00:00
assert . Equal ( c , len ( lines ) , 1 )
2015-05-01 01:13:18 +00:00
for _ , line := range lines {
f := strings . Fields ( line )
2019-09-09 21:05:56 +00:00
assert . Equal ( c , f [ 1 ] , originalImageID )
2015-05-01 01:13:18 +00:00
}
}
2016-01-21 01:09:11 +00:00
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsNotShowPortsOfStoppedContainer ( c * testing . T ) {
2016-01-22 02:48:21 +00:00
testRequires ( c , DaemonIsLinux )
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "run" , "--name=foo" , "-d" , "-p" , "6000:5000" , "busybox" , "top" )
cli . WaitRun ( c , "foo" )
ports := cli . DockerCmd ( c , "ps" , "--format" , "{{ .Ports }}" , "--filter" , "name=foo" ) . Stdout ( )
2021-02-11 20:45:16 +00:00
expected := ":6000->5000/tcp"
assert . Assert ( c , is . Contains ( ports , expected ) , "Expected: %v, got: %v" , expected , ports )
2016-01-21 01:09:11 +00:00
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "kill" , "foo" )
cli . DockerCmd ( c , "wait" , "foo" )
ports = cli . DockerCmd ( c , "ps" , "--format" , "{{ .Ports }}" , "--filter" , "name=foo" ) . Stdout ( )
2021-02-11 20:45:16 +00:00
assert . Equal ( c , ports , "" , "Should not got %v" , expected )
2016-01-21 01:09:11 +00:00
}
2016-02-03 22:46:01 +00:00
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsShowMounts ( c * testing . T ) {
2017-09-08 15:16:15 +00:00
existingContainers := ExistingContainerNames ( c )
2016-02-03 22:46:01 +00:00
prefix , slash := getPrefixAndSlashFromDaemonPlatform ( )
mp := prefix + slash + "test"
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "volume" , "create" , "ps-volume-test" )
2016-03-16 23:15:04 +00:00
// volume mount containers
2016-02-03 22:46:01 +00:00
runSleepingContainer ( c , "--name=volume-test-1" , "--volume" , "ps-volume-test:" + mp )
2023-07-27 10:53:23 +00:00
cli . WaitRun ( c , "volume-test-1" )
2016-02-03 22:46:01 +00:00
runSleepingContainer ( c , "--name=volume-test-2" , "--volume" , mp )
2023-07-27 10:53:23 +00:00
cli . WaitRun ( c , "volume-test-2" )
2016-03-16 23:15:04 +00:00
// bind mount container
var bindMountSource string
var bindMountDestination string
2016-12-16 14:13:23 +00:00
if DaemonIsWindows ( ) {
2023-07-05 10:12:16 +00:00
bindMountSource = ` c:\ `
bindMountDestination = ` c:\t `
2016-03-16 23:15:04 +00:00
} else {
bindMountSource = "/tmp"
bindMountDestination = "/t"
}
runSleepingContainer ( c , "--name=bind-mount-test" , "-v" , bindMountSource + ":" + bindMountDestination )
2023-07-27 10:53:23 +00:00
cli . WaitRun ( c , "bind-mount-test" )
2016-02-03 22:46:01 +00:00
2023-07-27 10:53:23 +00:00
out := cli . DockerCmd ( c , "ps" , "--format" , "{{.Names}} {{.Mounts}}" ) . Stdout ( )
2016-02-03 22:46:01 +00:00
2019-08-05 15:54:15 +00:00
lines := strings . Split ( strings . TrimSpace ( out ) , "\n" )
2017-09-08 15:16:15 +00:00
lines = RemoveLinesForExistingElements ( lines , existingContainers )
2019-04-04 13:23:19 +00:00
assert . Equal ( c , len ( lines ) , 3 )
2016-02-03 22:46:01 +00:00
fields := strings . Fields ( lines [ 0 ] )
2019-04-04 13:23:19 +00:00
assert . Equal ( c , len ( fields ) , 2 )
2019-09-09 21:05:56 +00:00
assert . Equal ( c , fields [ 0 ] , "bind-mount-test" )
assert . Equal ( c , fields [ 1 ] , bindMountSource )
2016-03-16 23:15:04 +00:00
fields = strings . Fields ( lines [ 1 ] )
2019-04-04 13:23:19 +00:00
assert . Equal ( c , len ( fields ) , 2 )
2016-02-03 22:46:01 +00:00
2017-05-21 23:24:07 +00:00
anonymousVolumeID := fields [ 1 ]
2016-02-03 22:46:01 +00:00
2016-03-16 23:15:04 +00:00
fields = strings . Fields ( lines [ 2 ] )
2019-09-09 21:05:56 +00:00
assert . Equal ( c , fields [ 1 ] , "ps-volume-test" )
2016-02-03 22:46:01 +00:00
// filter by volume name
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--format" , "{{.Names}} {{.Mounts}}" , "--filter" , "volume=ps-volume-test" ) . Stdout ( )
2016-02-03 22:46:01 +00:00
2019-08-05 15:54:15 +00:00
lines = strings . Split ( strings . TrimSpace ( out ) , "\n" )
2017-09-08 15:16:15 +00:00
lines = RemoveLinesForExistingElements ( lines , existingContainers )
2019-04-04 13:23:19 +00:00
assert . Equal ( c , len ( lines ) , 1 )
2016-02-03 22:46:01 +00:00
fields = strings . Fields ( lines [ 0 ] )
2019-09-09 21:05:56 +00:00
assert . Equal ( c , fields [ 1 ] , "ps-volume-test" )
2016-02-03 22:46:01 +00:00
// empty results filtering by unknown volume
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--format" , "{{.Names}} {{.Mounts}}" , "--filter" , "volume=this-volume-should-not-exist" ) . Stdout ( )
2019-08-05 15:54:15 +00:00
assert . Equal ( c , len ( strings . TrimSpace ( out ) ) , 0 )
2016-02-03 22:46:01 +00:00
// filter by mount destination
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--format" , "{{.Names}} {{.Mounts}}" , "--filter" , "volume=" + mp ) . Stdout ( )
2016-02-03 22:46:01 +00:00
2019-08-05 15:54:15 +00:00
lines = strings . Split ( strings . TrimSpace ( out ) , "\n" )
2017-09-08 15:16:15 +00:00
lines = RemoveLinesForExistingElements ( lines , existingContainers )
2019-04-04 13:23:19 +00:00
assert . Equal ( c , len ( lines ) , 2 )
2016-02-03 22:46:01 +00:00
fields = strings . Fields ( lines [ 0 ] )
2019-09-09 21:05:56 +00:00
assert . Equal ( c , fields [ 1 ] , anonymousVolumeID )
2016-02-03 22:46:01 +00:00
fields = strings . Fields ( lines [ 1 ] )
2019-09-09 21:05:56 +00:00
assert . Equal ( c , fields [ 1 ] , "ps-volume-test" )
2016-02-03 22:46:01 +00:00
2016-03-16 23:15:04 +00:00
// filter by bind mount source
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--format" , "{{.Names}} {{.Mounts}}" , "--filter" , "volume=" + bindMountSource ) . Stdout ( )
2016-03-16 23:15:04 +00:00
2019-08-05 15:54:15 +00:00
lines = strings . Split ( strings . TrimSpace ( out ) , "\n" )
2017-09-08 15:16:15 +00:00
lines = RemoveLinesForExistingElements ( lines , existingContainers )
2019-04-04 13:23:19 +00:00
assert . Equal ( c , len ( lines ) , 1 )
2016-03-16 23:15:04 +00:00
fields = strings . Fields ( lines [ 0 ] )
2019-04-04 13:23:19 +00:00
assert . Equal ( c , len ( fields ) , 2 )
2019-09-09 21:05:56 +00:00
assert . Equal ( c , fields [ 0 ] , "bind-mount-test" )
assert . Equal ( c , fields [ 1 ] , bindMountSource )
2016-03-16 23:15:04 +00:00
// filter by bind mount destination
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--format" , "{{.Names}} {{.Mounts}}" , "--filter" , "volume=" + bindMountDestination ) . Stdout ( )
2016-03-16 23:15:04 +00:00
2019-08-05 15:54:15 +00:00
lines = strings . Split ( strings . TrimSpace ( out ) , "\n" )
2017-09-08 15:16:15 +00:00
lines = RemoveLinesForExistingElements ( lines , existingContainers )
2019-04-04 13:23:19 +00:00
assert . Equal ( c , len ( lines ) , 1 )
2016-03-16 23:15:04 +00:00
fields = strings . Fields ( lines [ 0 ] )
2019-04-04 13:23:19 +00:00
assert . Equal ( c , len ( fields ) , 2 )
2019-09-09 21:05:56 +00:00
assert . Equal ( c , fields [ 0 ] , "bind-mount-test" )
assert . Equal ( c , fields [ 1 ] , bindMountSource )
2016-03-16 23:15:04 +00:00
2016-02-03 22:46:01 +00:00
// empty results filtering by unknown mount point
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--format" , "{{.Names}} {{.Mounts}}" , "--filter" , "volume=" + prefix + slash + "this-path-was-never-mounted" ) . Stdout ( )
2019-08-05 15:54:15 +00:00
assert . Equal ( c , len ( strings . TrimSpace ( out ) ) , 0 )
2016-02-03 22:46:01 +00:00
}
2016-04-14 09:43:15 +00:00
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsListContainersFilterNetwork ( c * testing . T ) {
2017-09-08 15:16:15 +00:00
existing := ExistingContainerIDs ( c )
2016-06-06 00:04:33 +00:00
// TODO default network on Windows is not called "bridge", and creating a
// custom network fails on Windows fails with "Error response from daemon: plugin not found")
testRequires ( c , DaemonIsLinux )
// create some containers
runSleepingContainer ( c , "--net=bridge" , "--name=onbridgenetwork" )
runSleepingContainer ( c , "--net=none" , "--name=onnonenetwork" )
// Filter docker ps on non existing network
2023-07-27 10:53:23 +00:00
out := cli . DockerCmd ( c , "ps" , "--filter" , "network=doesnotexist" ) . Stdout ( )
2019-08-05 15:54:15 +00:00
containerOut := strings . TrimSpace ( out )
2016-06-06 00:04:33 +00:00
lines := strings . Split ( containerOut , "\n" )
// skip header
lines = lines [ 1 : ]
// ps output should have no containers
2019-04-04 13:23:19 +00:00
assert . Equal ( c , len ( RemoveLinesForExistingElements ( lines , existing ) ) , 0 )
2016-05-27 19:20:31 +00:00
// Filter docker ps on network bridge
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--filter" , "network=bridge" ) . Stdout ( )
2019-08-05 15:54:15 +00:00
containerOut = strings . TrimSpace ( out )
2016-05-27 19:20:31 +00:00
2016-06-06 00:04:33 +00:00
lines = strings . Split ( containerOut , "\n" )
2016-05-27 19:20:31 +00:00
// skip header
lines = lines [ 1 : ]
// ps output should have only one container
2019-04-04 13:23:19 +00:00
assert . Equal ( c , len ( RemoveLinesForExistingElements ( lines , existing ) ) , 1 )
2016-05-27 19:20:31 +00:00
// Making sure onbridgenetwork is on the output
2019-09-09 21:08:22 +00:00
assert . Assert ( c , strings . Contains ( containerOut , "onbridgenetwork" ) , "Missing the container on network\n" )
2016-05-27 19:20:31 +00:00
// Filter docker ps on networks bridge and none
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--filter" , "network=bridge" , "--filter" , "network=none" ) . Stdout ( )
2019-08-05 15:54:15 +00:00
containerOut = strings . TrimSpace ( out )
2016-05-27 19:20:31 +00:00
lines = strings . Split ( containerOut , "\n" )
// skip header
lines = lines [ 1 : ]
2019-11-27 14:36:45 +00:00
// ps output should have both the containers
2019-04-04 13:23:19 +00:00
assert . Equal ( c , len ( RemoveLinesForExistingElements ( lines , existing ) ) , 2 )
2016-05-27 19:20:31 +00:00
// Making sure onbridgenetwork and onnonenetwork is on the output
2019-09-09 21:08:22 +00:00
assert . Assert ( c , strings . Contains ( containerOut , "onnonenetwork" ) , "Missing the container on none network\n" )
assert . Assert ( c , strings . Contains ( containerOut , "onbridgenetwork" ) , "Missing the container on bridge network\n" )
2023-07-27 10:53:23 +00:00
nwID := cli . DockerCmd ( c , "network" , "inspect" , "--format" , "{{.ID}}" , "bridge" ) . Stdout ( )
2016-06-06 00:04:33 +00:00
// Filter by network ID
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--filter" , "network=" + nwID ) . Stdout ( )
2019-08-05 15:54:15 +00:00
containerOut = strings . TrimSpace ( out )
2016-06-06 00:04:33 +00:00
2019-04-04 13:23:19 +00:00
assert . Assert ( c , is . Contains ( containerOut , "onbridgenetwork" ) )
2016-11-22 20:02:46 +00:00
// Filter by partial network ID
2023-07-27 10:53:23 +00:00
partialNwID := nwID [ 0 : 4 ]
2016-11-22 20:02:46 +00:00
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--filter" , "network=" + partialNwID ) . Stdout ( )
2019-08-05 15:54:15 +00:00
containerOut = strings . TrimSpace ( out )
2016-11-22 20:02:46 +00:00
lines = strings . Split ( containerOut , "\n" )
2017-09-08 15:16:15 +00:00
2016-11-22 20:02:46 +00:00
// skip header
lines = lines [ 1 : ]
// ps output should have only one container
2019-04-04 13:23:19 +00:00
assert . Equal ( c , len ( RemoveLinesForExistingElements ( lines , existing ) ) , 1 )
2016-11-22 20:02:46 +00:00
// Making sure onbridgenetwork is on the output
2019-09-09 21:08:22 +00:00
assert . Assert ( c , strings . Contains ( containerOut , "onbridgenetwork" ) , "Missing the container on network\n" )
2016-05-27 19:20:31 +00:00
}
2016-08-04 02:02:39 +00:00
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsByOrder ( c * testing . T ) {
2023-07-27 10:53:23 +00:00
container1 := runSleepingContainer ( c , "--name" , "xyz-abc" )
container2 := runSleepingContainer ( c , "--name" , "xyz-123" )
2016-08-04 02:02:39 +00:00
2018-07-09 17:40:34 +00:00
runSleepingContainer ( c , "--name" , "789-abc" )
runSleepingContainer ( c , "--name" , "789-123" )
2016-08-04 02:02:39 +00:00
// Run multiple time should have the same result
2023-07-27 10:53:23 +00:00
out := cli . DockerCmd ( c , "ps" , "--no-trunc" , "-q" , "-f" , "name=xyz" ) . Combined ( )
2019-04-04 13:23:19 +00:00
assert . Equal ( c , strings . TrimSpace ( out ) , fmt . Sprintf ( "%s\n%s" , container2 , container1 ) )
2016-08-04 02:02:39 +00:00
// Run multiple time should have the same result
2017-04-16 21:39:30 +00:00
out = cli . DockerCmd ( c , "ps" , "--no-trunc" , "-q" , "-f" , "name=xyz" ) . Combined ( )
2019-04-04 13:23:19 +00:00
assert . Equal ( c , strings . TrimSpace ( out ) , fmt . Sprintf ( "%s\n%s" , container2 , container1 ) )
2016-08-04 02:02:39 +00:00
}
2016-09-28 23:33:45 +00:00
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsListContainersFilterPorts ( c * testing . T ) {
2016-10-15 22:53:06 +00:00
testRequires ( c , DaemonIsLinux )
2017-09-15 13:16:38 +00:00
existingContainers := ExistingContainerIDs ( c )
2016-10-15 22:53:06 +00:00
2023-07-27 10:53:23 +00:00
out := cli . DockerCmd ( c , "run" , "-d" , "--publish=80" , "busybox" , "top" ) . Stdout ( )
2016-10-15 22:53:06 +00:00
id1 := strings . TrimSpace ( out )
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "run" , "-d" , "--expose=8080" , "busybox" , "top" ) . Stdout ( )
2016-10-15 22:53:06 +00:00
id2 := strings . TrimSpace ( out )
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "run" , "-d" , "-p" , "1090:90" , "busybox" , "top" ) . Stdout ( )
2020-02-01 17:34:54 +00:00
id3 := strings . TrimSpace ( out )
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--no-trunc" , "-q" ) . Stdout ( )
2019-09-09 21:08:22 +00:00
assert . Assert ( c , strings . Contains ( strings . TrimSpace ( out ) , id1 ) )
assert . Assert ( c , strings . Contains ( strings . TrimSpace ( out ) , id2 ) )
2020-02-01 17:34:54 +00:00
assert . Assert ( c , strings . Contains ( strings . TrimSpace ( out ) , id3 ) )
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--no-trunc" , "-q" , "--filter" , "publish=80-8080/udp" ) . Stdout ( )
2019-09-09 21:05:56 +00:00
assert . Assert ( c , strings . TrimSpace ( out ) != id1 )
assert . Assert ( c , strings . TrimSpace ( out ) != id2 )
2020-02-01 17:34:54 +00:00
assert . Assert ( c , strings . TrimSpace ( out ) != id3 )
2016-10-15 22:53:06 +00:00
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--no-trunc" , "-q" , "--filter" , "expose=8081" ) . Stdout ( )
2019-09-09 21:05:56 +00:00
assert . Assert ( c , strings . TrimSpace ( out ) != id1 )
assert . Assert ( c , strings . TrimSpace ( out ) != id2 )
2020-02-01 17:34:54 +00:00
assert . Assert ( c , strings . TrimSpace ( out ) != id3 )
2016-10-15 22:53:06 +00:00
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--no-trunc" , "-q" , "--filter" , "publish=80-81" ) . Stdout ( )
2020-02-01 17:34:54 +00:00
assert . Assert ( c , strings . TrimSpace ( out ) != id1 )
2019-09-09 21:05:56 +00:00
assert . Assert ( c , strings . TrimSpace ( out ) != id2 )
2020-02-01 17:34:54 +00:00
assert . Assert ( c , strings . TrimSpace ( out ) != id3 )
2016-10-15 22:53:06 +00:00
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--no-trunc" , "-q" , "--filter" , "expose=80/tcp" ) . Stdout ( )
2019-04-04 13:23:19 +00:00
assert . Equal ( c , strings . TrimSpace ( out ) , id1 )
2019-09-09 21:05:56 +00:00
assert . Assert ( c , strings . TrimSpace ( out ) != id2 )
2020-02-01 17:34:54 +00:00
assert . Assert ( c , strings . TrimSpace ( out ) != id3 )
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--no-trunc" , "-q" , "--filter" , "publish=1090" ) . Stdout ( )
2020-02-01 17:34:54 +00:00
assert . Assert ( c , strings . TrimSpace ( out ) != id1 )
assert . Assert ( c , strings . TrimSpace ( out ) != id2 )
assert . Equal ( c , strings . TrimSpace ( out ) , id3 )
2016-10-15 22:53:06 +00:00
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--no-trunc" , "-q" , "--filter" , "expose=8080/tcp" ) . Stdout ( )
2017-09-15 13:16:38 +00:00
out = RemoveOutputForExistingElements ( out , existingContainers )
2019-09-09 21:05:56 +00:00
assert . Assert ( c , strings . TrimSpace ( out ) != id1 )
2019-04-04 13:23:19 +00:00
assert . Equal ( c , strings . TrimSpace ( out ) , id2 )
2020-02-01 17:34:54 +00:00
assert . Assert ( c , strings . TrimSpace ( out ) != id3 )
2016-10-15 22:53:06 +00:00
}
2017-07-14 09:25:09 +00:00
2022-06-16 21:32:10 +00:00
func ( s * DockerCLIPsSuite ) TestPsNotShowLinknamesOfDeletedContainer ( c * testing . T ) {
2023-12-04 22:26:00 +00:00
testRequires ( c , DaemonIsLinux )
2017-09-08 15:16:15 +00:00
existingContainers := ExistingContainerNames ( c )
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "create" , "--name=aaa" , "busybox" , "top" )
cli . DockerCmd ( c , "create" , "--name=bbb" , "--link=aaa" , "busybox" , "top" )
2017-07-14 09:25:09 +00:00
2023-07-27 10:53:23 +00:00
out := cli . DockerCmd ( c , "ps" , "--no-trunc" , "-a" , "--format" , "{{.Names}}" ) . Stdout ( )
2019-08-05 15:54:15 +00:00
lines := strings . Split ( strings . TrimSpace ( out ) , "\n" )
2017-09-08 15:16:15 +00:00
lines = RemoveLinesForExistingElements ( lines , existingContainers )
2017-07-14 09:25:09 +00:00
expected := [ ] string { "bbb" , "aaa,bbb/aaa" }
var names [ ] string
names = append ( names , lines ... )
2019-04-04 13:23:19 +00:00
assert . Assert ( c , is . DeepEqual ( names , expected ) , "Expected array with non-truncated names: %v, got: %v" , expected , names )
2017-07-14 09:25:09 +00:00
2023-07-27 10:53:23 +00:00
cli . DockerCmd ( c , "rm" , "bbb" )
2017-07-14 09:25:09 +00:00
2023-07-27 10:53:23 +00:00
out = cli . DockerCmd ( c , "ps" , "--no-trunc" , "-a" , "--format" , "{{.Names}}" ) . Stdout ( )
2017-09-08 15:16:15 +00:00
out = RemoveOutputForExistingElements ( out , existingContainers )
2019-04-04 13:23:19 +00:00
assert . Equal ( c , strings . TrimSpace ( out ) , "aaa" )
2017-07-14 09:25:09 +00:00
}