@@ -734,3 +734,56 @@ func (s *DockerSuite) TestPsNotShowPortsOfStoppedContainer(c *check.C) {
734734 fields = strings .Fields (lines [1 ])
735735 c .Assert (fields [len (fields )- 2 ], checker .Not (checker .Equals ), expected , check .Commentf ("Should not got %v" , expected ))
736736}
737+
738+ func (s * DockerSuite ) TestPsShowMounts (c * check.C ) {
739+ prefix , slash := getPrefixAndSlashFromDaemonPlatform ()
740+
741+ mp := prefix + slash + "test"
742+
743+ dockerCmd (c , "volume" , "create" , "--name" , "ps-volume-test" )
744+ runSleepingContainer (c , "--name=volume-test-1" , "--volume" , "ps-volume-test:" + mp )
745+ c .Assert (waitRun ("volume-test-1" ), checker .IsNil )
746+ runSleepingContainer (c , "--name=volume-test-2" , "--volume" , mp )
747+ c .Assert (waitRun ("volume-test-2" ), checker .IsNil )
748+
749+ out , _ := dockerCmd (c , "ps" , "--format" , "{{.Names}} {{.Mounts}}" )
750+
751+ lines := strings .Split (strings .TrimSpace (string (out )), "\n " )
752+ c .Assert (lines , checker .HasLen , 2 )
753+
754+ fields := strings .Fields (lines [0 ])
755+ c .Assert (fields , checker .HasLen , 2 )
756+
757+ annonymounsVolumeID := fields [1 ]
758+
759+ fields = strings .Fields (lines [1 ])
760+ c .Assert (fields [1 ], checker .Equals , "ps-volume-test" )
761+
762+ // filter by volume name
763+ out , _ = dockerCmd (c , "ps" , "--format" , "{{.Names}} {{.Mounts}}" , "--filter" , "volume=ps-volume-test" )
764+
765+ lines = strings .Split (strings .TrimSpace (string (out )), "\n " )
766+ c .Assert (lines , checker .HasLen , 1 )
767+
768+ fields = strings .Fields (lines [0 ])
769+ c .Assert (fields [1 ], checker .Equals , "ps-volume-test" )
770+
771+ // empty results filtering by unknown volume
772+ out , _ = dockerCmd (c , "ps" , "--format" , "{{.Names}} {{.Mounts}}" , "--filter" , "volume=this-volume-should-not-exist" )
773+ c .Assert (strings .TrimSpace (string (out )), checker .HasLen , 0 )
774+
775+ // filter by mount destination
776+ out , _ = dockerCmd (c , "ps" , "--format" , "{{.Names}} {{.Mounts}}" , "--filter" , "volume=" + mp )
777+
778+ lines = strings .Split (strings .TrimSpace (string (out )), "\n " )
779+ c .Assert (lines , checker .HasLen , 2 )
780+
781+ fields = strings .Fields (lines [0 ])
782+ c .Assert (fields [1 ], checker .Equals , annonymounsVolumeID )
783+ fields = strings .Fields (lines [1 ])
784+ c .Assert (fields [1 ], checker .Equals , "ps-volume-test" )
785+
786+ // empty results filtering by unknown mount point
787+ out , _ = dockerCmd (c , "ps" , "--format" , "{{.Names}} {{.Mounts}}" , "--filter" , "volume=" + prefix + slash + "this-path-was-never-mounted" )
788+ c .Assert (strings .TrimSpace (string (out )), checker .HasLen , 0 )
789+ }
0 commit comments