Merge pull request #36450 from yongtang/02282018-enhancement
Enhancement of replacing ContainerCreate with helper funcs in tests Upstream-commit: fa018b433a4baa552ffbeb5d53d5674c6467b8e5 Component: engine
This commit is contained in:
@ -9,8 +9,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
"github.com/docker/docker/integration/internal/container"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
@ -36,22 +36,14 @@ func TestContainerStartOnDaemonRestart(t *testing.T) {
|
||||
assert.NoError(t, err, "error creating client")
|
||||
|
||||
ctx := context.Background()
|
||||
c, err := client.ContainerCreate(ctx,
|
||||
&container.Config{
|
||||
Image: "busybox",
|
||||
Cmd: []string{"top"},
|
||||
},
|
||||
nil,
|
||||
nil,
|
||||
"",
|
||||
)
|
||||
assert.NoError(t, err, "error creating test container")
|
||||
defer client.ContainerRemove(ctx, c.ID, types.ContainerRemoveOptions{Force: true})
|
||||
|
||||
err = client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{})
|
||||
cID := container.Create(t, ctx, client)
|
||||
defer client.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
|
||||
|
||||
err = client.ContainerStart(ctx, cID, types.ContainerStartOptions{})
|
||||
assert.NoError(t, err, "error starting test container")
|
||||
|
||||
inspect, err := client.ContainerInspect(ctx, c.ID)
|
||||
inspect, err := client.ContainerInspect(ctx, cID)
|
||||
assert.NoError(t, err, "error getting inspect data")
|
||||
|
||||
ppid := getContainerdShimPid(t, inspect)
|
||||
@ -67,7 +59,7 @@ func TestContainerStartOnDaemonRestart(t *testing.T) {
|
||||
|
||||
d.Start(t, "--iptables=false")
|
||||
|
||||
err = client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{})
|
||||
err = client.ContainerStart(ctx, cID, types.ContainerStartOptions{})
|
||||
assert.NoError(t, err, "failed to start test container")
|
||||
}
|
||||
|
||||
|
||||
@ -5,9 +5,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/integration/internal/container"
|
||||
"github.com/docker/docker/integration/internal/request"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -18,23 +17,9 @@ func TestPsFilter(t *testing.T) {
|
||||
client := request.NewAPIClient(t)
|
||||
ctx := context.Background()
|
||||
|
||||
createContainerForFilter := func(ctx context.Context, name string) string {
|
||||
body, err := client.ContainerCreate(ctx,
|
||||
&container.Config{
|
||||
Cmd: []string{"top"},
|
||||
Image: "busybox",
|
||||
},
|
||||
&container.HostConfig{},
|
||||
&network.NetworkingConfig{},
|
||||
name,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
return body.ID
|
||||
}
|
||||
|
||||
prev := createContainerForFilter(ctx, "prev")
|
||||
createContainerForFilter(ctx, "top")
|
||||
next := createContainerForFilter(ctx, "next")
|
||||
prev := container.Create(t, ctx, client, container.WithName("prev"))
|
||||
container.Create(t, ctx, client, container.WithName("top"))
|
||||
next := container.Create(t, ctx, client, container.WithName("next"))
|
||||
|
||||
containerIDs := func(containers []types.Container) []string {
|
||||
entries := []string{}
|
||||
|
||||
Reference in New Issue
Block a user