@@ -11,15 +11,18 @@ import (
1111
1212func TestContainerRename (t * testing.T ) {
1313 oldName := "old_name_" + t .Name ()
14- result := icmd .RunCommand ("docker" , "run" , "-d" , "--name" , oldName , fixtures .AlpineImage , "sleep" , "60" )
15- result .Assert (t , icmd .Success )
16- containerID := strings .TrimSpace (result .Stdout ())
14+ res := icmd .RunCommand ("docker" , "run" , "-d" , "--name" , oldName , fixtures .AlpineImage , "sleep" , "60" )
15+ res .Assert (t , icmd .Success )
16+ cID := strings .TrimSpace (res .Stdout ())
17+ t .Cleanup (func () {
18+ icmd .RunCommand ("docker" , "container" , "rm" , "-f" , cID ).Assert (t , icmd .Success )
19+ })
1720
1821 newName := "new_name_" + t .Name ()
19- renameResult : = icmd .RunCommand ("docker" , "container" , "rename" , oldName , newName )
20- renameResult .Assert (t , icmd .Success )
22+ res = icmd .RunCommand ("docker" , "container" , "rename" , oldName , newName )
23+ res .Assert (t , icmd .Success )
2124
22- inspectResult : = icmd .RunCommand ("docker" , "inspect" , "--format" , "{{.Name}}" , containerID )
23- inspectResult .Assert (t , icmd .Success )
24- assert .Equal (t , "/" + newName , strings .TrimSpace (inspectResult .Stdout ()))
25+ res = icmd .RunCommand ("docker" , "container" , " inspect" , "--format" , "{{.Name}}" , cID )
26+ res .Assert (t , icmd .Success )
27+ assert .Equal (t , "/" + newName , strings .TrimSpace (res .Stdout ()))
2528}
0 commit comments