From e52c8b00180a1f8fb1358a8994df64c049cd06fb Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Sat, 21 Apr 2018 19:42:20 +0000 Subject: [PATCH] Some improvement in restart_test.go This fix consists of some improvement in restart_test.go by replacing Fatal with assert, so that they are consistent with other tests in integration/container. Signed-off-by: Yong Tang Upstream-commit: 67535921b32f68863f7a882d2300b59e0bbeffa4 Component: engine --- .../integration/container/restart_test.go | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/components/engine/integration/container/restart_test.go b/components/engine/integration/container/restart_test.go index d6deea730e..630c50f42b 100644 --- a/components/engine/integration/container/restart_test.go +++ b/components/engine/integration/container/restart_test.go @@ -9,6 +9,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/internal/test/daemon" + "github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/skip" ) @@ -40,9 +41,8 @@ func TestDaemonRestartKillContainers(t *testing.T) { for _, liveRestoreEnabled := range []bool{false, true} { for fnName, stopDaemon := range map[string]func(*testing.T, *daemon.Daemon){ "kill-daemon": func(t *testing.T, d *daemon.Daemon) { - if err := d.Kill(); err != nil { - t.Fatal(err) - } + err := d.Kill() + assert.NilError(t, err) }, "stop-daemon": func(t *testing.T, d *daemon.Daemon) { d.Stop(t) @@ -57,9 +57,7 @@ func TestDaemonRestartKillContainers(t *testing.T) { d := daemon.New(t) client, err := d.NewClient() - if err != nil { - t.Fatal(err) - } + assert.NilError(t, err) args := []string{"--iptables=false"} if liveRestoreEnabled { @@ -71,14 +69,11 @@ func TestDaemonRestartKillContainers(t *testing.T) { ctx := context.Background() resp, err := client.ContainerCreate(ctx, c.config, c.hostConfig, nil, "") - if err != nil { - t.Fatal(err) - } + assert.NilError(t, err) defer client.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true}) - if err := client.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil { - t.Fatal(err) - } + err = client.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}) + assert.NilError(t, err) stopDaemon(t, d) d.Start(t, args...) @@ -91,9 +86,7 @@ func TestDaemonRestartKillContainers(t *testing.T) { var running bool for i := 0; i < 30; i++ { inspect, err := client.ContainerInspect(ctx, resp.ID) - if err != nil { - t.Fatal(err) - } + assert.NilError(t, err) running = inspect.State.Running if running == expected { @@ -102,10 +95,7 @@ func TestDaemonRestartKillContainers(t *testing.T) { time.Sleep(2 * time.Second) } - - if running != expected { - t.Fatalf("got unexpected running state, expected %v, got: %v", expected, running) - } + assert.Equal(t, expected, running, "got unexpected running state, expected %v, got: %v", expected, running) // TODO(cpuguy83): test pause states... this seems to be rather undefined currently }) }