mirror of
https://github.com/moby/moby.git
synced 2025-07-30 18:23:29 +03:00
Better test cleanup with defer
This fixes a few misuses of `deleteAllContainers()` cleanup method in integration-cli suite by moving call to the beginning of the method and guaranteeing their execution (including panics) with `defer`s. Also added some forgotten cleanup calls while I'm at it. Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
This commit is contained in:
@ -14,6 +14,8 @@ import (
|
||||
)
|
||||
|
||||
func TestContainerApiGetAll(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
startCount, err := getContainerCount()
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot query container count: %v", err)
|
||||
@ -46,12 +48,12 @@ func TestContainerApiGetAll(t *testing.T) {
|
||||
t.Fatalf("Container Name mismatch. Expected: %q, received: %q\n", "/"+name, actual)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("container REST API - check GET json/all=1")
|
||||
}
|
||||
|
||||
func TestContainerApiGetExport(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
name := "exportcontainer"
|
||||
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
@ -82,12 +84,13 @@ func TestContainerApiGetExport(t *testing.T) {
|
||||
if !found {
|
||||
t.Fatalf("The created test file has not been found in the exported image")
|
||||
}
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("container REST API - check GET containers/export")
|
||||
}
|
||||
|
||||
func TestContainerApiGetChanges(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
name := "changescontainer"
|
||||
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "rm", "/etc/passwd")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
@ -119,8 +122,6 @@ func TestContainerApiGetChanges(t *testing.T) {
|
||||
t.Fatalf("/etc/passwd has been removed but is not present in the diff")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("container REST API - check GET containers/changes")
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user