瀏覽代碼

Enhancement of replacing ContainerCreate with helper funcs in tests

This fix is a minor enhancement to replace several ContainerCreate with
helper funcs of `container.Create` in tests.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Yong Tang 7 年之前
父節點
當前提交
6ad4720c78
共有 2 個文件被更改,包括 12 次插入35 次删除
  1. 8 16
      integration/container/daemon_linux_test.go
  2. 4 19
      integration/container/ps_test.go

+ 8 - 16
integration/container/daemon_linux_test.go

@@ -9,8 +9,8 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/docker/docker/api/types"
 	"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-cli/daemon"
+	"github.com/docker/docker/integration/internal/container"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/assert"
 	"golang.org/x/sys/unix"
 	"golang.org/x/sys/unix"
 )
 )
@@ -36,22 +36,14 @@ func TestContainerStartOnDaemonRestart(t *testing.T) {
 	assert.NoError(t, err, "error creating client")
 	assert.NoError(t, err, "error creating client")
 
 
 	ctx := context.Background()
 	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")
 	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")
 	assert.NoError(t, err, "error getting inspect data")
 
 
 	ppid := getContainerdShimPid(t, inspect)
 	ppid := getContainerdShimPid(t, inspect)
@@ -67,7 +59,7 @@ func TestContainerStartOnDaemonRestart(t *testing.T) {
 
 
 	d.Start(t, "--iptables=false")
 	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")
 	assert.NoError(t, err, "failed to start test container")
 }
 }
 
 

+ 4 - 19
integration/container/ps_test.go

@@ -5,9 +5,8 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/docker/docker/api/types"
 	"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/filters"
-	"github.com/docker/docker/api/types/network"
+	"github.com/docker/docker/integration/internal/container"
 	"github.com/docker/docker/integration/internal/request"
 	"github.com/docker/docker/integration/internal/request"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/require"
@@ -18,23 +17,9 @@ func TestPsFilter(t *testing.T) {
 	client := request.NewAPIClient(t)
 	client := request.NewAPIClient(t)
 	ctx := context.Background()
 	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 {
 	containerIDs := func(containers []types.Container) []string {
 		entries := []string{}
 		entries := []string{}