mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix docker volume dangling filter
The docker volume ls -f dangling=true filter was inverted; the filtered results actually returned all non-dangling volumes. This fixes the filter and adds some integration tests to test the correct behavior. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
7ce97dbe30
commit
1cbf9047b3
2 changed files with 36 additions and 1 deletions
|
@ -381,7 +381,7 @@ func (daemon *Daemon) Volumes(filter string) ([]*types.Volume, error) {
|
|||
|
||||
volumes := daemon.volumes.List()
|
||||
for _, v := range volumes {
|
||||
if filterUsed && daemon.volumes.Count(v) == 0 {
|
||||
if filterUsed && daemon.volumes.Count(v) > 0 {
|
||||
continue
|
||||
}
|
||||
volumesOut = append(volumesOut, volumeToAPIType(v))
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
|
@ -54,6 +55,40 @@ func (s *DockerSuite) TestVolumeCliLs(c *check.C) {
|
|||
c.Assert(strings.Contains(out, "test\n"), check.Equals, true)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCliLsFilterDangling(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
dockerCmd(c, "volume", "create", "--name", "testnotinuse1")
|
||||
dockerCmd(c, "volume", "create", "--name", "testisinuse1")
|
||||
dockerCmd(c, "volume", "create", "--name", "testisinuse2")
|
||||
|
||||
// Make sure both "created" (but not started), and started
|
||||
// containers are included in reference counting
|
||||
dockerCmd(c, "run", "--name", "volume-test1", "-v", "testisinuse1:/foo", "busybox", "true")
|
||||
dockerCmd(c, "create", "--name", "volume-test2", "-v", "testisinuse2:/foo", "busybox", "true")
|
||||
|
||||
out, _ := dockerCmd(c, "volume", "ls")
|
||||
|
||||
// No filter, all volumes should show
|
||||
c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
|
||||
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
|
||||
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
|
||||
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=false")
|
||||
|
||||
// Same as above, but expicitly disabling dangling
|
||||
c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
|
||||
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
|
||||
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
|
||||
|
||||
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=true")
|
||||
|
||||
// Filter "dangling" volumes; ony "dangling" (unused) volumes should be in the output
|
||||
c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
|
||||
c.Assert(out, check.Not(checker.Contains), "testisinuse1\n", check.Commentf("volume 'testisinuse1' in output, but not expected"))
|
||||
c.Assert(out, check.Not(checker.Contains), "testisinuse2\n", check.Commentf("volume 'testisinuse2' in output, but not expected"))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCliRm(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "volume", "create")
|
||||
|
|
Loading…
Reference in a new issue