From 196af472a6b423ed0547c0fb080aa548cd077efd Mon Sep 17 00:00:00 2001 From: weiyan Date: Wed, 14 Oct 2015 17:29:13 +0800 Subject: [PATCH] use of checkers on docker_cli_restart_test.go Signed-off-by: weiyan --- integration-cli/docker_cli_restart_test.go | 84 ++++++++-------------- 1 file changed, 30 insertions(+), 54 deletions(-) diff --git a/integration-cli/docker_cli_restart_test.go b/integration-cli/docker_cli_restart_test.go index da38056d68..bb71e7d2bd 100644 --- a/integration-cli/docker_cli_restart_test.go +++ b/integration-cli/docker_cli_restart_test.go @@ -4,6 +4,7 @@ import ( "strings" "time" + "github.com/docker/docker/pkg/integration/checker" "github.com/go-check/check" ) @@ -15,16 +16,12 @@ func (s *DockerSuite) TestRestartStoppedContainer(c *check.C) { dockerCmd(c, "wait", cleanedContainerID) out, _ = dockerCmd(c, "logs", cleanedContainerID) - if out != "foobar\n" { - c.Errorf("container should've printed 'foobar'") - } + c.Assert(out, checker.Equals, "foobar\n") dockerCmd(c, "restart", cleanedContainerID) out, _ = dockerCmd(c, "logs", cleanedContainerID) - if out != "foobar\nfoobar\n" { - c.Errorf("container should've printed 'foobar' twice, got %v", out) - } + c.Assert(out, checker.Equals, "foobar\nfoobar\n") } func (s *DockerSuite) TestRestartRunningContainer(c *check.C) { @@ -33,22 +30,18 @@ func (s *DockerSuite) TestRestartRunningContainer(c *check.C) { cleanedContainerID := strings.TrimSpace(out) - c.Assert(waitRun(cleanedContainerID), check.IsNil) + c.Assert(waitRun(cleanedContainerID), checker.IsNil) out, _ = dockerCmd(c, "logs", cleanedContainerID) - if out != "foobar\n" { - c.Errorf("container should've printed 'foobar'") - } + c.Assert(out, checker.Equals, "foobar\n") dockerCmd(c, "restart", "-t", "1", cleanedContainerID) out, _ = dockerCmd(c, "logs", cleanedContainerID) - c.Assert(waitRun(cleanedContainerID), check.IsNil) + c.Assert(waitRun(cleanedContainerID), checker.IsNil) - if out != "foobar\nfoobar\n" { - c.Errorf("container should've printed 'foobar' twice") - } + c.Assert(out, checker.Equals, "foobar\nfoobar\n") } // Test that restarting a container with a volume does not create a new volume on restart. Regression test for #819. @@ -58,27 +51,21 @@ func (s *DockerSuite) TestRestartWithVolumes(c *check.C) { cleanedContainerID := strings.TrimSpace(out) out, _ = dockerCmd(c, "inspect", "--format", "{{ len .Mounts }}", cleanedContainerID) - - if out = strings.Trim(out, " \n\r"); out != "1" { - c.Errorf("expect 1 volume received %s", out) - } + out = strings.Trim(out, " \n\r") + c.Assert(out, checker.Equals, "1") source, err := inspectMountSourceField(cleanedContainerID, "/test") - c.Assert(err, check.IsNil) + c.Assert(err, checker.IsNil) dockerCmd(c, "restart", cleanedContainerID) out, _ = dockerCmd(c, "inspect", "--format", "{{ len .Mounts }}", cleanedContainerID) - if out = strings.Trim(out, " \n\r"); out != "1" { - c.Errorf("expect 1 volume after restart received %s", out) - } + out = strings.Trim(out, " \n\r") + c.Assert(out, checker.Equals, "1") sourceAfterRestart, err := inspectMountSourceField(cleanedContainerID, "/test") - c.Assert(err, check.IsNil) - - if source != sourceAfterRestart { - c.Errorf("expected volume path: %s Actual path: %s", source, sourceAfterRestart) - } + c.Assert(err, checker.IsNil) + c.Assert(source, checker.Equals, sourceAfterRestart) } func (s *DockerSuite) TestRestartPolicyNO(c *check.C) { @@ -87,10 +74,8 @@ func (s *DockerSuite) TestRestartPolicyNO(c *check.C) { id := strings.TrimSpace(string(out)) name, err := inspectField(id, "HostConfig.RestartPolicy.Name") - c.Assert(err, check.IsNil) - if name != "no" { - c.Fatalf("Container restart policy name is %s, expected %s", name, "no") - } + c.Assert(err, checker.IsNil) + c.Assert(name, checker.Equals, "no") } func (s *DockerSuite) TestRestartPolicyAlways(c *check.C) { @@ -99,18 +84,14 @@ func (s *DockerSuite) TestRestartPolicyAlways(c *check.C) { id := strings.TrimSpace(string(out)) name, err := inspectField(id, "HostConfig.RestartPolicy.Name") - c.Assert(err, check.IsNil) - if name != "always" { - c.Fatalf("Container restart policy name is %s, expected %s", name, "always") - } + c.Assert(err, checker.IsNil) + c.Assert(name, checker.Equals, "always") MaximumRetryCount, err := inspectField(id, "HostConfig.RestartPolicy.MaximumRetryCount") - c.Assert(err, check.IsNil) + c.Assert(err, checker.IsNil) // MaximumRetryCount=0 if the restart policy is always - if MaximumRetryCount != "0" { - c.Fatalf("Container Maximum Retry Count is %s, expected %s", MaximumRetryCount, "0") - } + c.Assert(MaximumRetryCount, checker.Equals, "0") } func (s *DockerSuite) TestRestartPolicyOnFailure(c *check.C) { @@ -119,10 +100,8 @@ func (s *DockerSuite) TestRestartPolicyOnFailure(c *check.C) { id := strings.TrimSpace(string(out)) name, err := inspectField(id, "HostConfig.RestartPolicy.Name") - c.Assert(err, check.IsNil) - if name != "on-failure" { - c.Fatalf("Container restart policy name is %s, expected %s", name, "on-failure") - } + c.Assert(err, checker.IsNil) + c.Assert(name, checker.Equals, "on-failure") } @@ -133,18 +112,15 @@ func (s *DockerSuite) TestContainerRestartwithGoodContainer(c *check.C) { out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "true") id := strings.TrimSpace(string(out)) - if err := waitInspect(id, "{{ .State.Restarting }} {{ .State.Running }}", "false false", 5*time.Second); err != nil { - c.Fatal(err) - } + err := waitInspect(id, "{{ .State.Restarting }} {{ .State.Running }}", "false false", 5*time.Second) + c.Assert(err, checker.IsNil) + count, err := inspectField(id, "RestartCount") - c.Assert(err, check.IsNil) - if count != "0" { - c.Fatalf("Container was restarted %s times, expected %d", count, 0) - } + c.Assert(err, checker.IsNil) + c.Assert(count, checker.Equals, "0") + MaximumRetryCount, err := inspectField(id, "HostConfig.RestartPolicy.MaximumRetryCount") - c.Assert(err, check.IsNil) - if MaximumRetryCount != "3" { - c.Fatalf("Container Maximum Retry Count is %s, expected %s", MaximumRetryCount, "3") - } + c.Assert(err, checker.IsNil) + c.Assert(MaximumRetryCount, checker.Equals, "3") }