@@ -806,15 +806,30 @@ func (s *DockerSuite) TestPsFormatSize(c *check.C) {
806806}
807807
808808func (s * DockerSuite ) TestPsListContainersFilterNetwork (c * check.C ) {
809- // create a container
810- out , _ := runSleepingContainer (c , "--net=bridge" , "--name=onbridgenetwork" )
811- out , _ = runSleepingContainer (c , "--net=none" , "--name=onnonenetwork" )
809+ // TODO default network on Windows is not called "bridge", and creating a
810+ // custom network fails on Windows fails with "Error response from daemon: plugin not found")
811+ testRequires (c , DaemonIsLinux )
812+
813+ // create some containers
814+ runSleepingContainer (c , "--net=bridge" , "--name=onbridgenetwork" )
815+ runSleepingContainer (c , "--net=none" , "--name=onnonenetwork" )
816+
817+ // Filter docker ps on non existing network
818+ out , _ := dockerCmd (c , "ps" , "--filter" , "network=doesnotexist" )
819+ containerOut := strings .TrimSpace (string (out ))
820+ lines := strings .Split (containerOut , "\n " )
821+
822+ // skip header
823+ lines = lines [1 :]
824+
825+ // ps output should have no containers
826+ c .Assert (lines , checker .HasLen , 0 )
812827
813828 // Filter docker ps on network bridge
814829 out , _ = dockerCmd (c , "ps" , "--filter" , "network=bridge" )
815- containerOut : = strings .TrimSpace (string (out ))
830+ containerOut = strings .TrimSpace (string (out ))
816831
817- lines : = strings .Split (containerOut , "\n " )
832+ lines = strings .Split (containerOut , "\n " )
818833
819834 // skip header
820835 lines = lines [1 :]
@@ -823,7 +838,7 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
823838 c .Assert (lines , checker .HasLen , 1 )
824839
825840 // Making sure onbridgenetwork is on the output
826- c .Assert (lines [ 0 ] , checker .Contains , "onbridgenetwork" , check .Commentf ("Missing the container on network\n " ))
841+ c .Assert (containerOut , checker .Contains , "onbridgenetwork" , check .Commentf ("Missing the container on network\n " ))
827842
828843 // Filter docker ps on networks bridge and none
829844 out , _ = dockerCmd (c , "ps" , "--filter" , "network=bridge" , "--filter" , "network=none" )
@@ -838,6 +853,14 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
838853 c .Assert (lines , checker .HasLen , 2 )
839854
840855 // Making sure onbridgenetwork and onnonenetwork is on the output
841- c .Assert (lines [0 ], checker .Contains , "onnonenetwork" , check .Commentf ("Missing the container on none network\n " ))
842- c .Assert (lines [1 ], checker .Contains , "onbridgenetwork" , check .Commentf ("Missing the container on bridge network\n " ))
856+ c .Assert (containerOut , checker .Contains , "onnonenetwork" , check .Commentf ("Missing the container on none network\n " ))
857+ c .Assert (containerOut , checker .Contains , "onbridgenetwork" , check .Commentf ("Missing the container on bridge network\n " ))
858+
859+ nwID , _ := dockerCmd (c , "network" , "inspect" , "--format" , "{{.ID}}" , "bridge" )
860+
861+ // Filter by network ID
862+ out , _ = dockerCmd (c , "ps" , "--filter" , "network=" + nwID )
863+ containerOut = strings .TrimSpace (string (out ))
864+
865+ c .Assert (containerOut , checker .Contains , "onbridgenetwork" )
843866}
0 commit comments