github.com/gdevillele/moby@v1.13.0/integration-cli/docker_cli_update_test.go (about)

     1  package main
     2  
     3  import (
     4  	"strings"
     5  	"time"
     6  
     7  	"github.com/docker/docker/pkg/integration/checker"
     8  	"github.com/go-check/check"
     9  )
    10  
    11  func (s *DockerSuite) TestUpdateRestartPolicy(c *check.C) {
    12  	out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "sh", "-c", "sleep 1 && false")
    13  	timeout := 60 * time.Second
    14  	if daemonPlatform == "windows" {
    15  		timeout = 180 * time.Second
    16  	}
    17  
    18  	id := strings.TrimSpace(string(out))
    19  
    20  	// update restart policy to on-failure:5
    21  	dockerCmd(c, "update", "--restart=on-failure:5", id)
    22  
    23  	err := waitExited(id, timeout)
    24  	c.Assert(err, checker.IsNil)
    25  
    26  	count := inspectField(c, id, "RestartCount")
    27  	c.Assert(count, checker.Equals, "5")
    28  
    29  	maximumRetryCount := inspectField(c, id, "HostConfig.RestartPolicy.MaximumRetryCount")
    30  	c.Assert(maximumRetryCount, checker.Equals, "5")
    31  }
    32  
    33  func (s *DockerSuite) TestUpdateRestartWithAutoRemoveFlag(c *check.C) {
    34  	out, _ := runSleepingContainer(c, "--rm")
    35  	id := strings.TrimSpace(out)
    36  
    37  	// update restart policy for an AutoRemove container
    38  	out, _, err := dockerCmdWithError("update", "--restart=always", id)
    39  	c.Assert(err, checker.NotNil)
    40  	c.Assert(out, checker.Contains, "Restart policy cannot be updated because AutoRemove is enabled for the container")
    41  }