Selaa lähdekoodia

Merge pull request #17788 from haoshuwei/modify-volume-inspect-multi

Modify docker volume inspect to return existed volumes and the names of the unexsited volumes
Sebastiaan van Stijn 9 vuotta sitten
vanhempi
commit
5b4734aaa5
2 muutettua tiedostoa jossa 20 lisäystä ja 1 poistoa
  1. 7 1
      api/client/volume.go
  2. 13 0
      integration-cli/docker_cli_volume_test.go

+ 7 - 1
api/client/volume.go

@@ -5,6 +5,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"io"
+	"net/http"
 	"net/url"
 	"text/tabwriter"
 	"text/template"
@@ -128,7 +129,12 @@ func (cli *DockerCli) CmdVolumeInspect(args ...string) error {
 	for _, name := range cmd.Args() {
 		resp, err := cli.call("GET", "/volumes/"+name, nil, nil)
 		if err != nil {
-			return err
+			if resp.statusCode != http.StatusNotFound {
+				return err
+			}
+			status = 1
+			fmt.Fprintf(cli.err, "Error: No such volume: %s\n", name)
+			continue
 		}
 
 		var volume types.Volume

+ 13 - 0
integration-cli/docker_cli_volume_test.go

@@ -50,6 +50,19 @@ func (s *DockerSuite) TestVolumeCliInspect(c *check.C) {
 	c.Assert(strings.TrimSpace(out), check.Equals, "test")
 }
 
+func (s *DockerSuite) TestVolumeCliInspectMulti(c *check.C) {
+	dockerCmd(c, "volume", "create", "--name", "test1")
+	dockerCmd(c, "volume", "create", "--name", "test2")
+
+	out, _ := dockerCmd(c, "volume", "inspect", "--format='{{ .Name }}'", "test1", "test2", "doesntexist")
+	outArr := strings.Split(strings.TrimSpace(out), "\n")
+	c.Assert(len(outArr), check.Equals, 3, check.Commentf("\n%s", out))
+
+	c.Assert(strings.Contains(out, "test1\n"), check.Equals, true)
+	c.Assert(strings.Contains(out, "test2\n"), check.Equals, true)
+	c.Assert(strings.Contains(out, "Error: No such volume: doesntexist\n"), check.Equals, true)
+}
+
 func (s *DockerSuite) TestVolumeCliLs(c *check.C) {
 	prefix := ""
 	if daemonPlatform == "windows" {