Merge pull request #16404 from duglin/FixRenameError

Fix 'rename' error msg and error checking
This commit is contained in:
Evan Hazlett 2015-09-21 15:51:02 -04:00
Родитель 732676fad5 848792c42e
Коммит 0c71c19239
3 изменённых файлов: 16 добавлений и 3 удалений

Просмотреть файл

@ -2,6 +2,7 @@ package client
import (
"fmt"
"strings"
Cli "github.com/docker/docker/cli"
flag "github.com/docker/docker/pkg/mflag"
@ -16,8 +17,12 @@ func (cli *DockerCli) CmdRename(args ...string) error {
cmd.ParseFlags(args, true)
oldName := cmd.Arg(0)
newName := cmd.Arg(1)
oldName := strings.TrimSpace(cmd.Arg(0))
newName := strings.TrimSpace(cmd.Arg(1))
if oldName == "" || newName == "" {
return fmt.Errorf("Error: Neither old nor new names may be empty")
}
if _, _, err := readBody(cli.call("POST", fmt.Sprintf("/containers/%s/rename?name=%s", oldName, newName), nil, nil)); err != nil {
fmt.Fprintf(cli.err, "%s\n", err)

Просмотреть файл

@ -9,7 +9,7 @@ import (
// reserved.
func (daemon *Daemon) ContainerRename(oldName, newName string) error {
if oldName == "" || newName == "" {
return fmt.Errorf("usage: docker rename OLD_NAME NEW_NAME")
return fmt.Errorf("Neither old nor new names may be empty")
}
container, err := daemon.Get(oldName)

Просмотреть файл

@ -74,6 +74,14 @@ func (s *DockerSuite) TestRenameInvalidName(c *check.C) {
c.Fatalf("Renaming container to invalid name should have failed: %s\n%v", out, err)
}
if out, _, err := dockerCmdWithError("rename", "myname", ""); err == nil || !strings.Contains(out, "may be empty") {
c.Fatalf("Renaming container to empty name should have failed: %s\n%v", out, err)
}
if out, _, err := dockerCmdWithError("rename", "", "newname"); err == nil || !strings.Contains(out, "may be empty") {
c.Fatalf("Renaming container to empty name should have failed: %s\n%v", out, err)
}
if out, _, err := dockerCmdWithError("ps", "-a"); err != nil || !strings.Contains(out, "myname") {
c.Fatalf("Output of docker ps should have included 'myname': %s\n%v", out, err)
}