瀏覽代碼

fix volume ls filter driver

Signed-off-by: allencloud <allen.sun@daocloud.io>
allencloud 8 年之前
父節點
當前提交
0fdab49610
共有 3 個文件被更改,包括 34 次插入16 次删除
  1. 1 1
      daemon/list.go
  2. 2 2
      docs/reference/commandline/volume_ls.md
  3. 31 13
      integration-cli/docker_cli_volume_test.go

+ 1 - 1
daemon/list.go

@@ -623,7 +623,7 @@ func (daemon *Daemon) filterVolumes(vols []volume.Volume, filter filters.Args) (
 			}
 			}
 		}
 		}
 		if filter.Include("driver") {
 		if filter.Include("driver") {
-			if !filter.Match("driver", vol.DriverName()) {
+			if !filter.ExactMatch("driver", vol.DriverName()) {
 				continue
 				continue
 			}
 			}
 		}
 		}

+ 2 - 2
docs/reference/commandline/volume_ls.md

@@ -76,9 +76,9 @@ local               rosemary
 
 
 ### driver
 ### driver
 
 
-The `driver` filter matches on all or part of a volume's driver name.
+The `driver` filter matches volumes based on their driver.
 
 
-The following filter matches all volumes with a driver name containing the `local` string.
+The following example matches volumes that are created with the `local` driver:
 
 
 ```bash
 ```bash
 $ docker volume ls -f driver=local
 $ docker volume ls -f driver=local

+ 31 - 13
integration-cli/docker_cli_volume_test.go

@@ -184,19 +184,6 @@ func (s *DockerSuite) TestVolumeCLILsFilterDangling(c *check.C) {
 	c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
 	c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
 	c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("execpeted volume 'testisinuse1' in output"))
 	c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("execpeted volume 'testisinuse1' in output"))
 	c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
 	c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
-
-	out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=invalidDriver")
-	outArr := strings.Split(strings.TrimSpace(out), "\n")
-	c.Assert(len(outArr), check.Equals, 1, check.Commentf("%s\n", out))
-
-	out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=local")
-	outArr = strings.Split(strings.TrimSpace(out), "\n")
-	c.Assert(len(outArr), check.Equals, 4, check.Commentf("\n%s", out))
-
-	out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=loc")
-	outArr = strings.Split(strings.TrimSpace(out), "\n")
-	c.Assert(len(outArr), check.Equals, 4, check.Commentf("\n%s", out))
-
 }
 }
 
 
 func (s *DockerSuite) TestVolumeCLILsErrorWithInvalidFilterName(c *check.C) {
 func (s *DockerSuite) TestVolumeCLILsErrorWithInvalidFilterName(c *check.C) {
@@ -377,6 +364,37 @@ func (s *DockerSuite) TestVolumeCLILsFilterLabels(c *check.C) {
 	c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
 	c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
 }
 }
 
 
+func (s *DockerSuite) TestVolumeCLILsFilterDrivers(c *check.C) {
+	// using default volume driver local to create volumes
+	testVol1 := "testvol-1"
+	out, _, err := dockerCmdWithError("volume", "create", testVol1)
+	c.Assert(err, check.IsNil)
+
+	testVol2 := "testvol-2"
+	out, _, err = dockerCmdWithError("volume", "create", testVol2)
+	c.Assert(err, check.IsNil)
+
+	// filter with driver=local
+	out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=local")
+	c.Assert(out, checker.Contains, "testvol-1\n", check.Commentf("expected volume 'testvol-1' in output"))
+	c.Assert(out, checker.Contains, "testvol-2\n", check.Commentf("expected volume 'testvol-2' in output"))
+
+	// filter with driver=invaliddriver
+	out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=invaliddriver")
+	outArr := strings.Split(strings.TrimSpace(out), "\n")
+	c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
+
+	// filter with driver=loca
+	out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=loca")
+	outArr = strings.Split(strings.TrimSpace(out), "\n")
+	c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
+
+	// filter with driver=
+	out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=")
+	outArr = strings.Split(strings.TrimSpace(out), "\n")
+	c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
+}
+
 func (s *DockerSuite) TestVolumeCLIRmForceUsage(c *check.C) {
 func (s *DockerSuite) TestVolumeCLIRmForceUsage(c *check.C) {
 	out, _ := dockerCmd(c, "volume", "create")
 	out, _ := dockerCmd(c, "volume", "create")
 	id := strings.TrimSpace(out)
 	id := strings.TrimSpace(out)