mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Modify docker volume inspect to return existed volumes
Signed-off-by: Shuwei Hao <haoshuwei24@gmail.com>
This commit is contained in:
parent
1ddd4b1dcc
commit
6295345005
2 changed files with 20 additions and 1 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
@ -127,8 +128,13 @@ func (cli *DockerCli) CmdVolumeInspect(args ...string) error {
|
||||||
for _, name := range cmd.Args() {
|
for _, name := range cmd.Args() {
|
||||||
resp, err := cli.call("GET", "/volumes/"+name, nil, nil)
|
resp, err := cli.call("GET", "/volumes/"+name, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.statusCode != http.StatusNotFound {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
status = 1
|
||||||
|
fmt.Fprintf(cli.err, "Error: No such volume: %s\n", name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
var volume types.Volume
|
var volume types.Volume
|
||||||
if err := json.NewDecoder(resp.body).Decode(&volume); err != nil {
|
if err := json.NewDecoder(resp.body).Decode(&volume); err != nil {
|
||||||
|
|
|
@ -50,6 +50,19 @@ func (s *DockerSuite) TestVolumeCliInspect(c *check.C) {
|
||||||
c.Assert(strings.TrimSpace(out), check.Equals, "test")
|
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) {
|
func (s *DockerSuite) TestVolumeCliLs(c *check.C) {
|
||||||
prefix := ""
|
prefix := ""
|
||||||
if daemonPlatform == "windows" {
|
if daemonPlatform == "windows" {
|
||||||
|
|
Loading…
Reference in a new issue