Browse code

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 authored on 2018/03/01 06:35:56
Showing 2 changed files
... ...
@@ -9,8 +9,8 @@ import (
9 9
 	"testing"
10 10
 
11 11
 	"github.com/docker/docker/api/types"
12
-	"github.com/docker/docker/api/types/container"
13 12
 	"github.com/docker/docker/integration-cli/daemon"
13
+	"github.com/docker/docker/integration/internal/container"
14 14
 	"github.com/stretchr/testify/assert"
15 15
 	"golang.org/x/sys/unix"
16 16
 )
... ...
@@ -36,22 +36,14 @@ func TestContainerStartOnDaemonRestart(t *testing.T) {
36 36
 	assert.NoError(t, err, "error creating client")
37 37
 
38 38
 	ctx := context.Background()
39
-	c, err := client.ContainerCreate(ctx,
40
-		&container.Config{
41
-			Image: "busybox",
42
-			Cmd:   []string{"top"},
43
-		},
44
-		nil,
45
-		nil,
46
-		"",
47
-	)
48
-	assert.NoError(t, err, "error creating test container")
49
-	defer client.ContainerRemove(ctx, c.ID, types.ContainerRemoveOptions{Force: true})
50
-
51
-	err = client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{})
39
+
40
+	cID := container.Create(t, ctx, client)
41
+	defer client.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
42
+
43
+	err = client.ContainerStart(ctx, cID, types.ContainerStartOptions{})
52 44
 	assert.NoError(t, err, "error starting test container")
53 45
 
54
-	inspect, err := client.ContainerInspect(ctx, c.ID)
46
+	inspect, err := client.ContainerInspect(ctx, cID)
55 47
 	assert.NoError(t, err, "error getting inspect data")
56 48
 
57 49
 	ppid := getContainerdShimPid(t, inspect)
... ...
@@ -67,7 +59,7 @@ func TestContainerStartOnDaemonRestart(t *testing.T) {
67 67
 
68 68
 	d.Start(t, "--iptables=false")
69 69
 
70
-	err = client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{})
70
+	err = client.ContainerStart(ctx, cID, types.ContainerStartOptions{})
71 71
 	assert.NoError(t, err, "failed to start test container")
72 72
 }
73 73
 
... ...
@@ -5,9 +5,8 @@ import (
5 5
 	"testing"
6 6
 
7 7
 	"github.com/docker/docker/api/types"
8
-	"github.com/docker/docker/api/types/container"
9 8
 	"github.com/docker/docker/api/types/filters"
10
-	"github.com/docker/docker/api/types/network"
9
+	"github.com/docker/docker/integration/internal/container"
11 10
 	"github.com/docker/docker/integration/internal/request"
12 11
 	"github.com/stretchr/testify/assert"
13 12
 	"github.com/stretchr/testify/require"
... ...
@@ -18,23 +17,9 @@ func TestPsFilter(t *testing.T) {
18 18
 	client := request.NewAPIClient(t)
19 19
 	ctx := context.Background()
20 20
 
21
-	createContainerForFilter := func(ctx context.Context, name string) string {
22
-		body, err := client.ContainerCreate(ctx,
23
-			&container.Config{
24
-				Cmd:   []string{"top"},
25
-				Image: "busybox",
26
-			},
27
-			&container.HostConfig{},
28
-			&network.NetworkingConfig{},
29
-			name,
30
-		)
31
-		require.NoError(t, err)
32
-		return body.ID
33
-	}
34
-
35
-	prev := createContainerForFilter(ctx, "prev")
36
-	createContainerForFilter(ctx, "top")
37
-	next := createContainerForFilter(ctx, "next")
21
+	prev := container.Create(t, ctx, client, container.WithName("prev"))
22
+	container.Create(t, ctx, client, container.WithName("top"))
23
+	next := container.Create(t, ctx, client, container.WithName("next"))
38 24
 
39 25
 	containerIDs := func(containers []types.Container) []string {
40 26
 		entries := []string{}