Browse code

Some enhancement in integration tests

This fix converts some `client.ContainerCreate` to `container.Create`,
and removes some unneeded `name` fields when test containers are created.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

Yong Tang authored on 2018/04/15 01:52:02
Showing 3 changed files
... ...
@@ -46,7 +46,7 @@ func TestCreateFailsWhenIdentifierDoesNotExist(t *testing.T) {
46 46
 				&container.Config{Image: tc.image},
47 47
 				&container.HostConfig{},
48 48
 				&network.NetworkingConfig{},
49
-				"foo",
49
+				"",
50 50
 			)
51 51
 			testutil.ErrorContains(t, err, tc.expectedError)
52 52
 		})
... ...
@@ -86,7 +86,7 @@ func TestCreateWithInvalidEnv(t *testing.T) {
86 86
 				},
87 87
 				&container.HostConfig{},
88 88
 				&network.NetworkingConfig{},
89
-				"foo",
89
+				"",
90 90
 			)
91 91
 			testutil.ErrorContains(t, err, tc.expectedError)
92 92
 		})
... ...
@@ -7,7 +7,6 @@ import (
7 7
 	"time"
8 8
 
9 9
 	"github.com/docker/docker/api/types"
10
-	containerTypes "github.com/docker/docker/api/types/container"
11 10
 	"github.com/docker/docker/api/types/filters"
12 11
 	"github.com/docker/docker/integration/internal/container"
13 12
 	"github.com/docker/docker/integration/internal/request"
... ...
@@ -70,15 +69,10 @@ func TestExportContainerAfterDaemonRestart(t *testing.T) {
70 70
 	defer d.Stop(t)
71 71
 
72 72
 	ctx := context.Background()
73
-	cfg := containerTypes.Config{
74
-		Image: "busybox",
75
-		Cmd:   []string{"top"},
76
-	}
77
-	ctr, err := client.ContainerCreate(ctx, &cfg, nil, nil, "")
78
-	assert.NilError(t, err)
73
+	ctrID := container.Create(t, ctx, client)
79 74
 
80 75
 	d.Restart(t)
81 76
 
82
-	_, err = client.ContainerExport(ctx, ctr.ID)
77
+	_, err = client.ContainerExport(ctx, ctrID)
83 78
 	assert.NilError(t, err)
84 79
 }
... ...
@@ -6,7 +6,7 @@ import (
6 6
 	"testing"
7 7
 
8 8
 	"github.com/docker/docker/api/types"
9
-	"github.com/docker/docker/api/types/container"
9
+	"github.com/docker/docker/integration/internal/container"
10 10
 	"github.com/docker/docker/internal/test/daemon"
11 11
 
12 12
 	"github.com/gotestyourself/gotestyourself/assert"
... ...
@@ -40,25 +40,17 @@ func TestCgroupDriverSystemdMemoryLimit(t *testing.T) {
40 40
 	defer d.Stop(t)
41 41
 
42 42
 	const mem = 64 * 1024 * 1024 // 64 MB
43
-	cfg := container.Config{
44
-		Image: "busybox",
45
-		Cmd:   []string{"top"},
46
-	}
47
-	hostcfg := container.HostConfig{
48
-		Resources: container.Resources{
49
-			Memory: mem,
50
-		},
51
-	}
52 43
 
53 44
 	ctx := context.Background()
54
-	ctr, err := client.ContainerCreate(ctx, &cfg, &hostcfg, nil, "")
55
-	assert.NilError(t, err)
56
-	defer client.ContainerRemove(ctx, ctr.ID, types.ContainerRemoveOptions{Force: true})
45
+	ctrID := container.Create(t, ctx, client, func(c *container.TestContainerConfig) {
46
+		c.HostConfig.Resources.Memory = mem
47
+	})
48
+	defer client.ContainerRemove(ctx, ctrID, types.ContainerRemoveOptions{Force: true})
57 49
 
58
-	err = client.ContainerStart(ctx, ctr.ID, types.ContainerStartOptions{})
50
+	err = client.ContainerStart(ctx, ctrID, types.ContainerStartOptions{})
59 51
 	assert.NilError(t, err)
60 52
 
61
-	s, err := client.ContainerInspect(ctx, ctr.ID)
53
+	s, err := client.ContainerInspect(ctx, ctrID)
62 54
 	assert.NilError(t, err)
63 55
 	assert.Equal(t, s.HostConfig.Memory, mem)
64 56
 }