1
0
mirror of https://github.com/moby/moby.git synced 2025-07-29 07:21:35 +03:00

client: ContainerStop(), ContainerRestart(): support stop-signal

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2022-02-16 11:36:37 +01:00
parent 9060126639
commit e8fa708ae5
12 changed files with 68 additions and 40 deletions

View File

@ -913,8 +913,8 @@ func (s *DockerSuite) TestContainerAPIRestart(c *testing.T) {
assert.NilError(c, err)
defer cli.Close()
timeout := 1 * time.Second
err = cli.ContainerRestart(context.Background(), name, &timeout)
timeout := 1
err = cli.ContainerRestart(context.Background(), name, container.StopOptions{Timeout: &timeout})
assert.NilError(c, err)
assert.Assert(c, waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second) == nil)
@ -930,7 +930,7 @@ func (s *DockerSuite) TestContainerAPIRestartNotimeoutParam(c *testing.T) {
assert.NilError(c, err)
defer cli.Close()
err = cli.ContainerRestart(context.Background(), name, nil)
err = cli.ContainerRestart(context.Background(), name, container.StopOptions{})
assert.NilError(c, err)
assert.Assert(c, waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second) == nil)
@ -965,19 +965,23 @@ func (s *DockerSuite) TestContainerAPIStart(c *testing.T) {
func (s *DockerSuite) TestContainerAPIStop(c *testing.T) {
name := "test-api-stop"
runSleepingContainer(c, "-i", "--name", name)
timeout := 30 * time.Second
timeout := 30
cli, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err)
defer cli.Close()
err = cli.ContainerStop(context.Background(), name, &timeout)
err = cli.ContainerStop(context.Background(), name, container.StopOptions{
Timeout: &timeout,
})
assert.NilError(c, err)
assert.Assert(c, waitInspect(name, "{{ .State.Running }}", "false", 60*time.Second) == nil)
// second call to start should give 304
// maybe add ContainerStartWithRaw to test it
err = cli.ContainerStop(context.Background(), name, &timeout)
err = cli.ContainerStop(context.Background(), name, container.StopOptions{
Timeout: &timeout,
})
assert.NilError(c, err)
}
@ -1255,7 +1259,7 @@ func (s *DockerSuite) TestContainerAPIPostContainerStop(c *testing.T) {
assert.NilError(c, err)
defer cli.Close()
err = cli.ContainerStop(context.Background(), containerID, nil)
err = cli.ContainerStop(context.Background(), containerID, container.StopOptions{})
assert.NilError(c, err)
assert.Assert(c, waitInspect(containerID, "{{ .State.Running }}", "false", 60*time.Second) == nil)
}