Skip to content

Commit 7f8f117

Browse files
committed
fixed TestContainerAPIRename test
Signed-off-by: carsontham <carsontham@outlook.com>
1 parent 90d84f3 commit 7f8f117

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

e2e/container/rename_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ import (
1111

1212
func 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

Comments
 (0)