Browse code

fix volume ls filter driver

Signed-off-by: allencloud <allen.sun@daocloud.io>

allencloud authored on 2017/01/04 15:43:29
Showing 3 changed files
... ...
@@ -623,7 +623,7 @@ func (daemon *Daemon) filterVolumes(vols []volume.Volume, filter filters.Args) (
623 623
 			}
624 624
 		}
625 625
 		if filter.Include("driver") {
626
-			if !filter.Match("driver", vol.DriverName()) {
626
+			if !filter.ExactMatch("driver", vol.DriverName()) {
627 627
 				continue
628 628
 			}
629 629
 		}
... ...
@@ -76,9 +76,9 @@ local               rosemary
76 76
 
77 77
 ### driver
78 78
 
79
-The `driver` filter matches on all or part of a volume's driver name.
79
+The `driver` filter matches volumes based on their driver.
80 80
 
81
-The following filter matches all volumes with a driver name containing the `local` string.
81
+The following example matches volumes that are created with the `local` driver:
82 82
 
83 83
 ```bash
84 84
 $ docker volume ls -f driver=local
... ...
@@ -184,19 +184,6 @@ func (s *DockerSuite) TestVolumeCLILsFilterDangling(c *check.C) {
184 184
 	c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
185 185
 	c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("execpeted volume 'testisinuse1' in output"))
186 186
 	c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
187
-
188
-	out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=invalidDriver")
189
-	outArr := strings.Split(strings.TrimSpace(out), "\n")
190
-	c.Assert(len(outArr), check.Equals, 1, check.Commentf("%s\n", out))
191
-
192
-	out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=local")
193
-	outArr = strings.Split(strings.TrimSpace(out), "\n")
194
-	c.Assert(len(outArr), check.Equals, 4, check.Commentf("\n%s", out))
195
-
196
-	out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=loc")
197
-	outArr = strings.Split(strings.TrimSpace(out), "\n")
198
-	c.Assert(len(outArr), check.Equals, 4, check.Commentf("\n%s", out))
199
-
200 187
 }
201 188
 
202 189
 func (s *DockerSuite) TestVolumeCLILsErrorWithInvalidFilterName(c *check.C) {
... ...
@@ -377,6 +364,37 @@ func (s *DockerSuite) TestVolumeCLILsFilterLabels(c *check.C) {
377 377
 	c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
378 378
 }
379 379
 
380
+func (s *DockerSuite) TestVolumeCLILsFilterDrivers(c *check.C) {
381
+	// using default volume driver local to create volumes
382
+	testVol1 := "testvol-1"
383
+	out, _, err := dockerCmdWithError("volume", "create", testVol1)
384
+	c.Assert(err, check.IsNil)
385
+
386
+	testVol2 := "testvol-2"
387
+	out, _, err = dockerCmdWithError("volume", "create", testVol2)
388
+	c.Assert(err, check.IsNil)
389
+
390
+	// filter with driver=local
391
+	out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=local")
392
+	c.Assert(out, checker.Contains, "testvol-1\n", check.Commentf("expected volume 'testvol-1' in output"))
393
+	c.Assert(out, checker.Contains, "testvol-2\n", check.Commentf("expected volume 'testvol-2' in output"))
394
+
395
+	// filter with driver=invaliddriver
396
+	out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=invaliddriver")
397
+	outArr := strings.Split(strings.TrimSpace(out), "\n")
398
+	c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
399
+
400
+	// filter with driver=loca
401
+	out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=loca")
402
+	outArr = strings.Split(strings.TrimSpace(out), "\n")
403
+	c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
404
+
405
+	// filter with driver=
406
+	out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=")
407
+	outArr = strings.Split(strings.TrimSpace(out), "\n")
408
+	c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
409
+}
410
+
380 411
 func (s *DockerSuite) TestVolumeCLIRmForceUsage(c *check.C) {
381 412
 	out, _ := dockerCmd(c, "volume", "create")
382 413
 	id := strings.TrimSpace(out)