Browse code

Update TestPsShowMounts to also test bind mounts

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>

Kenfe-Mickael Laventure authored on 2016/03/17 08:15:04
Showing 1 changed files
... ...
@@ -764,22 +764,40 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
764 764
 	mp := prefix + slash + "test"
765 765
 
766 766
 	dockerCmd(c, "volume", "create", "--name", "ps-volume-test")
767
+	// volume mount containers
767 768
 	runSleepingContainer(c, "--name=volume-test-1", "--volume", "ps-volume-test:"+mp)
768 769
 	c.Assert(waitRun("volume-test-1"), checker.IsNil)
769 770
 	runSleepingContainer(c, "--name=volume-test-2", "--volume", mp)
770 771
 	c.Assert(waitRun("volume-test-2"), checker.IsNil)
772
+	// bind mount container
773
+	var bindMountSource string
774
+	var bindMountDestination string
775
+	if DaemonIsWindows.Condition() {
776
+		bindMountSource = "c:\\"
777
+		bindMountDestination = "c:\\t"
778
+	} else {
779
+		bindMountSource = "/tmp"
780
+		bindMountDestination = "/t"
781
+	}
782
+	runSleepingContainer(c, "--name=bind-mount-test", "-v", bindMountSource+":"+bindMountDestination)
783
+	c.Assert(waitRun("bind-mount-test"), checker.IsNil)
771 784
 
772 785
 	out, _ := dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}")
773 786
 
774 787
 	lines := strings.Split(strings.TrimSpace(string(out)), "\n")
775
-	c.Assert(lines, checker.HasLen, 2)
788
+	c.Assert(lines, checker.HasLen, 3)
776 789
 
777 790
 	fields := strings.Fields(lines[0])
778 791
 	c.Assert(fields, checker.HasLen, 2)
792
+	c.Assert(fields[0], checker.Equals, "bind-mount-test")
793
+	c.Assert(fields[1], checker.Equals, bindMountSource)
794
+
795
+	fields = strings.Fields(lines[1])
796
+	c.Assert(fields, checker.HasLen, 2)
779 797
 
780 798
 	annonymounsVolumeID := fields[1]
781 799
 
782
-	fields = strings.Fields(lines[1])
800
+	fields = strings.Fields(lines[2])
783 801
 	c.Assert(fields[1], checker.Equals, "ps-volume-test")
784 802
 
785 803
 	// filter by volume name
... ...
@@ -806,6 +824,28 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
806 806
 	fields = strings.Fields(lines[1])
807 807
 	c.Assert(fields[1], checker.Equals, "ps-volume-test")
808 808
 
809
+	// filter by bind mount source
810
+	out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+bindMountSource)
811
+
812
+	lines = strings.Split(strings.TrimSpace(string(out)), "\n")
813
+	c.Assert(lines, checker.HasLen, 1)
814
+
815
+	fields = strings.Fields(lines[0])
816
+	c.Assert(fields, checker.HasLen, 2)
817
+	c.Assert(fields[0], checker.Equals, "bind-mount-test")
818
+	c.Assert(fields[1], checker.Equals, bindMountSource)
819
+
820
+	// filter by bind mount destination
821
+	out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+bindMountDestination)
822
+
823
+	lines = strings.Split(strings.TrimSpace(string(out)), "\n")
824
+	c.Assert(lines, checker.HasLen, 1)
825
+
826
+	fields = strings.Fields(lines[0])
827
+	c.Assert(fields, checker.HasLen, 2)
828
+	c.Assert(fields[0], checker.Equals, "bind-mount-test")
829
+	c.Assert(fields[1], checker.Equals, bindMountSource)
830
+
809 831
 	// empty results filtering by unknown mount point
810 832
 	out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+prefix+slash+"this-path-was-never-mounted")
811 833
 	c.Assert(strings.TrimSpace(string(out)), checker.HasLen, 0)