mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Improvement in integration tests
This fix adds several improvement: 1. No need for explicit ContainerRemove as it has been handled in setupTest() 2. Added `container.WithImage` helper function and used it in commit tests. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
135f815fb4
commit
6ab465804b
3 changed files with 12 additions and 8 deletions
|
@ -20,7 +20,6 @@ func TestLogsFollowTailEmpty(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
id := container.Run(t, ctx, client, container.WithCmd("sleep", "100000"))
|
id := container.Run(t, ctx, client, container.WithCmd("sleep", "100000"))
|
||||||
defer client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true})
|
|
||||||
|
|
||||||
logs, err := client.ContainerLogs(ctx, id, types.ContainerLogsOptions{ShowStdout: true, Tail: "2"})
|
logs, err := client.ContainerLogs(ctx, id, types.ContainerLogsOptions{ShowStdout: true, Tail: "2"})
|
||||||
if logs != nil {
|
if logs != nil {
|
||||||
|
|
|
@ -5,7 +5,7 @@ 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/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"
|
||||||
|
@ -16,10 +16,9 @@ func TestCommitInheritsEnv(t *testing.T) {
|
||||||
client := request.NewAPIClient(t)
|
client := request.NewAPIClient(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
createResp1, err := client.ContainerCreate(ctx, &container.Config{Image: "busybox"}, nil, nil, "")
|
cID1 := container.Create(t, ctx, client)
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
commitResp1, err := client.ContainerCommit(ctx, createResp1.ID, types.ContainerCommitOptions{
|
commitResp1, err := client.ContainerCommit(ctx, cID1, types.ContainerCommitOptions{
|
||||||
Changes: []string{"ENV PATH=/bin"},
|
Changes: []string{"ENV PATH=/bin"},
|
||||||
Reference: "test-commit-image",
|
Reference: "test-commit-image",
|
||||||
})
|
})
|
||||||
|
@ -31,10 +30,9 @@ func TestCommitInheritsEnv(t *testing.T) {
|
||||||
expectedEnv1 := []string{"PATH=/bin"}
|
expectedEnv1 := []string{"PATH=/bin"}
|
||||||
assert.Equal(t, expectedEnv1, image1.Config.Env)
|
assert.Equal(t, expectedEnv1, image1.Config.Env)
|
||||||
|
|
||||||
createResp2, err := client.ContainerCreate(ctx, &container.Config{Image: image1.ID}, nil, nil, "")
|
cID2 := container.Create(t, ctx, client, container.WithImage(image1.ID))
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
commitResp2, err := client.ContainerCommit(ctx, createResp2.ID, types.ContainerCommitOptions{
|
commitResp2, err := client.ContainerCommit(ctx, cID2, types.ContainerCommitOptions{
|
||||||
Changes: []string{"ENV PATH=/usr/bin:$PATH"},
|
Changes: []string{"ENV PATH=/usr/bin:$PATH"},
|
||||||
Reference: "test-commit-image",
|
Reference: "test-commit-image",
|
||||||
})
|
})
|
||||||
|
|
|
@ -22,6 +22,13 @@ func WithLinks(links ...string) func(*TestContainerConfig) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithImage sets the image of the container
|
||||||
|
func WithImage(image string) func(*TestContainerConfig) {
|
||||||
|
return func(c *TestContainerConfig) {
|
||||||
|
c.Config.Image = image
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithCmd sets the comannds of the container
|
// WithCmd sets the comannds of the container
|
||||||
func WithCmd(cmds ...string) func(*TestContainerConfig) {
|
func WithCmd(cmds ...string) func(*TestContainerConfig) {
|
||||||
return func(c *TestContainerConfig) {
|
return func(c *TestContainerConfig) {
|
||||||
|
|
Loading…
Reference in a new issue