Merge pull request #17004 from echo33/docker_cli_restart_test
use of checkers on docker_cli_restart_test.go
This commit is contained in:
commit
0f00c36d65
1 changed files with 30 additions and 54 deletions
|
@ -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")
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue