Skip to content

Commit e636a2a

Browse files
committed
cli/container_rename: Move to API validation
Signed-off-by: Paweł Gronowski <[email protected]>
1 parent af255ac commit e636a2a

File tree

3 files changed

+24
-67
lines changed

3 files changed

+24
-67
lines changed

cli/command/container/rename.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package container
22

33
import (
4-
"errors"
54
"fmt"
65

76
"github.com/docker/cli/cli"
@@ -19,10 +18,6 @@ func newRenameCommand(dockerCLI command.Cli) *cobra.Command {
1918
Args: cli.ExactArgs(2),
2019
RunE: func(cmd *cobra.Command, args []string) error {
2120
oldName, newName := args[0], args[1]
22-
if newName == "" {
23-
// TODO(thaJeztah): remove once https://github.com/moby/moby/pull/51336 is merged and vendored.
24-
return errors.New("new name cannot be blank")
25-
}
2621
_, err := dockerCLI.Client().ContainerRename(cmd.Context(), oldName, client.ContainerRenameOptions{
2722
NewName: newName,
2823
})

cli/command/container/rename_test.go

Lines changed: 0 additions & 62 deletions
This file was deleted.

e2e/container/rename_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,27 @@ func TestContainerRename(t *testing.T) {
2626
res.Assert(t, icmd.Success)
2727
assert.Equal(t, "/"+newName, strings.TrimSpace(res.Stdout()))
2828
}
29+
30+
func TestContainerRenameEmptyOldName(t *testing.T) {
31+
res := icmd.RunCommand("docker", "container", "rename", "", "newName")
32+
res.Assert(t, icmd.Expected{
33+
ExitCode: 1,
34+
Err: "invalid container name or ID: value is empty",
35+
})
36+
}
37+
38+
func TestContainerRenameEmptyNewName(t *testing.T) {
39+
oldName := "old_name_" + t.Name()
40+
res := icmd.RunCommand("docker", "run", "-d", "--name", oldName, fixtures.AlpineImage, "sleep", "60")
41+
res.Assert(t, icmd.Success)
42+
cID := strings.TrimSpace(res.Stdout())
43+
t.Cleanup(func() {
44+
icmd.RunCommand("docker", "container", "rm", "-f", cID).Assert(t, icmd.Success)
45+
})
46+
47+
res = icmd.RunCommand("docker", "container", "rename", oldName, "")
48+
res.Assert(t, icmd.Expected{
49+
ExitCode: 1,
50+
Err: "new name cannot be blank",
51+
})
52+
}

0 commit comments

Comments
 (0)