mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05: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:
parent
a78ce5c228
commit
70407ce40c
16 changed files with 290 additions and 251 deletions
|
|
@ -8,6 +8,8 @@ import (
|
|||
)
|
||||
|
||||
func TestRestartStoppedContainer(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "foobar")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
|
|
@ -46,12 +48,12 @@ func TestRestartStoppedContainer(t *testing.T) {
|
|||
t.Errorf("container should've printed 'foobar' twice")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("restart - echo foobar for stopped container")
|
||||
}
|
||||
|
||||
func TestRestartRunningContainer(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "echo foobar && sleep 30 && echo 'should not print this'")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
|
|
@ -89,13 +91,13 @@ func TestRestartRunningContainer(t *testing.T) {
|
|||
t.Errorf("container should've printed 'foobar' twice")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("restart - echo foobar for running container")
|
||||
}
|
||||
|
||||
// Test that restarting a container with a volume does not create a new volume on restart. Regression test for #819.
|
||||
func TestRestartWithVolumes(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "-v", "/test", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
|
|
@ -147,8 +149,6 @@ func TestRestartWithVolumes(t *testing.T) {
|
|||
t.Errorf("expected volume path: %s Actual path: %s", volumes, volumesAfterRestart)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("restart - does not create a new volume on restart")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue