mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Migrate docker_cli_stop_test.go to api test
This fix migrate docker_cli_stop_test.go to api test Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
9d61e5c8c1
commit
4f378124ff
2 changed files with 55 additions and 17 deletions
|
@ -1,17 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestStopContainerWithRestartPolicyAlways(c *check.C) {
|
||||
dockerCmd(c, "run", "--name", "verifyRestart1", "-d", "--restart=always", "busybox", "false")
|
||||
dockerCmd(c, "run", "--name", "verifyRestart2", "-d", "--restart=always", "busybox", "false")
|
||||
|
||||
c.Assert(waitRun("verifyRestart1"), checker.IsNil)
|
||||
c.Assert(waitRun("verifyRestart2"), checker.IsNil)
|
||||
|
||||
dockerCmd(c, "stop", "verifyRestart1")
|
||||
dockerCmd(c, "stop", "verifyRestart2")
|
||||
}
|
|
@ -18,6 +18,46 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestStopContainerWithRestartPolicyAlways(t *testing.T) {
|
||||
defer setupTest(t)()
|
||||
client := request.NewAPIClient(t)
|
||||
ctx := context.Background()
|
||||
|
||||
names := []string{"verifyRestart1", "verifyRestart2"}
|
||||
for _, name := range names {
|
||||
resp, err := client.ContainerCreate(ctx,
|
||||
&container.Config{
|
||||
Cmd: []string{"false"},
|
||||
Image: "busybox",
|
||||
},
|
||||
&container.HostConfig{
|
||||
RestartPolicy: container.RestartPolicy{
|
||||
Name: "always",
|
||||
},
|
||||
},
|
||||
&network.NetworkingConfig{},
|
||||
name,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = client.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
for _, name := range names {
|
||||
poll.WaitOn(t, containerIsInState(ctx, client, name, "running", "restarting"), poll.WithDelay(100*time.Millisecond))
|
||||
}
|
||||
|
||||
for _, name := range names {
|
||||
err := client.ContainerStop(ctx, name, nil)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
for _, name := range names {
|
||||
poll.WaitOn(t, containerIsStopped(ctx, client, name), poll.WithDelay(100*time.Millisecond))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteDevicemapper(t *testing.T) {
|
||||
skip.IfCondition(t, testEnv.DaemonInfo.Driver != "devicemapper")
|
||||
|
||||
|
@ -72,3 +112,18 @@ func containerIsStopped(ctx context.Context, client client.APIClient, containerI
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func containerIsInState(ctx context.Context, client client.APIClient, containerID string, state ...string) func(log poll.LogT) poll.Result {
|
||||
return func(log poll.LogT) poll.Result {
|
||||
inspect, err := client.ContainerInspect(ctx, containerID)
|
||||
if err != nil {
|
||||
return poll.Error(err)
|
||||
}
|
||||
for _, v := range state {
|
||||
if inspect.State.Status == v {
|
||||
return poll.Success()
|
||||
}
|
||||
}
|
||||
return poll.Continue("waiting for container to be running, currently %s", inspect.State.Status)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue