@@ -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