Merge pull request #36862 from yongtang/04152018-container.Create

Some enhancement in integration tests
This commit is contained in:
Yong Tang 2018-04-15 09:12:52 -07:00 committed by GitHub
commit ea579a6194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 25 deletions

View File

@ -46,7 +46,7 @@ func TestCreateFailsWhenIdentifierDoesNotExist(t *testing.T) {
&container.Config{Image: tc.image},
&container.HostConfig{},
&network.NetworkingConfig{},
"foo",
"",
)
testutil.ErrorContains(t, err, tc.expectedError)
})
@ -86,7 +86,7 @@ func TestCreateWithInvalidEnv(t *testing.T) {
},
&container.HostConfig{},
&network.NetworkingConfig{},
"foo",
"",
)
testutil.ErrorContains(t, err, tc.expectedError)
})

View File

@ -7,7 +7,6 @@ import (
"time"
"github.com/docker/docker/api/types"
containerTypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/integration/internal/request"
@ -70,15 +69,10 @@ func TestExportContainerAfterDaemonRestart(t *testing.T) {
defer d.Stop(t)
ctx := context.Background()
cfg := containerTypes.Config{
Image: "busybox",
Cmd: []string{"top"},
}
ctr, err := client.ContainerCreate(ctx, &cfg, nil, nil, "")
assert.NilError(t, err)
ctrID := container.Create(t, ctx, client)
d.Restart(t)
_, err = client.ContainerExport(ctx, ctr.ID)
_, err = client.ContainerExport(ctx, ctrID)
assert.NilError(t, err)
}

View File

@ -6,7 +6,7 @@ import (
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/internal/test/daemon"
"github.com/gotestyourself/gotestyourself/assert"
@ -40,25 +40,17 @@ func TestCgroupDriverSystemdMemoryLimit(t *testing.T) {
defer d.Stop(t)
const mem = 64 * 1024 * 1024 // 64 MB
cfg := container.Config{
Image: "busybox",
Cmd: []string{"top"},
}
hostcfg := container.HostConfig{
Resources: container.Resources{
Memory: mem,
},
}
ctx := context.Background()
ctr, err := client.ContainerCreate(ctx, &cfg, &hostcfg, nil, "")
assert.NilError(t, err)
defer client.ContainerRemove(ctx, ctr.ID, types.ContainerRemoveOptions{Force: true})
ctrID := container.Create(t, ctx, client, func(c *container.TestContainerConfig) {
c.HostConfig.Resources.Memory = mem
})
defer client.ContainerRemove(ctx, ctrID, types.ContainerRemoveOptions{Force: true})
err = client.ContainerStart(ctx, ctr.ID, types.ContainerStartOptions{})
err = client.ContainerStart(ctx, ctrID, types.ContainerStartOptions{})
assert.NilError(t, err)
s, err := client.ContainerInspect(ctx, ctr.ID)
s, err := client.ContainerInspect(ctx, ctrID)
assert.NilError(t, err)
assert.Equal(t, s.HostConfig.Memory, mem)
}