Combine runSimpleContainer with runContainer for rename test
As there is already a runSimpleContainer, I think it makes sense to combine runSimpleContainer with runContainer for rename test to reduce code duplication. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
30a8c6c109
commit
203d871658
|
@ -7,22 +7,11 @@ import (
|
||||||
"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/container"
|
||||||
"github.com/docker/docker/api/types/network"
|
"github.com/docker/docker/api/types/network"
|
||||||
"github.com/docker/docker/api/types/strslice"
|
|
||||||
"github.com/docker/docker/client"
|
|
||||||
"github.com/docker/docker/integration/util/request"
|
"github.com/docker/docker/integration/util/request"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func runContainer(ctx context.Context, t *testing.T, client client.APIClient, cntCfg *container.Config, hstCfg *container.HostConfig, nwkCfg *network.NetworkingConfig, cntName string) string {
|
|
||||||
cnt, err := client.ContainerCreate(ctx, cntCfg, hstCfg, nwkCfg, cntName)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
err = client.ContainerStart(ctx, cnt.ID, types.ContainerStartOptions{})
|
|
||||||
require.NoError(t, err)
|
|
||||||
return cnt.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
// This test simulates the scenario mentioned in #31392:
|
// This test simulates the scenario mentioned in #31392:
|
||||||
// Having two linked container, renaming the target and bringing a replacement
|
// Having two linked container, renaming the target and bringing a replacement
|
||||||
// and then deleting and recreating the source container linked to the new target.
|
// and then deleting and recreating the source container linked to the new target.
|
||||||
|
@ -32,57 +21,25 @@ func TestRenameLinkedContainer(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client := request.NewAPIClient(t)
|
client := request.NewAPIClient(t)
|
||||||
|
|
||||||
cntConfig := &container.Config{
|
aID := runSimpleContainer(ctx, t, client, "a0")
|
||||||
Image: "busybox",
|
|
||||||
Tty: true,
|
|
||||||
Cmd: strslice.StrSlice([]string{"top"}),
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
bID := runSimpleContainer(ctx, t, client, "b0", func(config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig) {
|
||||||
aID, bID string
|
hostConfig.Links = []string{"a0"}
|
||||||
cntJSON types.ContainerJSON
|
})
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
aID = runContainer(ctx, t, client,
|
err := client.ContainerRename(ctx, aID, "a1")
|
||||||
cntConfig,
|
|
||||||
&container.HostConfig{},
|
|
||||||
&network.NetworkingConfig{},
|
|
||||||
"a0",
|
|
||||||
)
|
|
||||||
|
|
||||||
bID = runContainer(ctx, t, client,
|
|
||||||
cntConfig,
|
|
||||||
&container.HostConfig{
|
|
||||||
Links: []string{"a0"},
|
|
||||||
},
|
|
||||||
&network.NetworkingConfig{},
|
|
||||||
"b0",
|
|
||||||
)
|
|
||||||
|
|
||||||
err = client.ContainerRename(ctx, aID, "a1")
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
runContainer(ctx, t, client,
|
runSimpleContainer(ctx, t, client, "a0")
|
||||||
cntConfig,
|
|
||||||
&container.HostConfig{},
|
|
||||||
&network.NetworkingConfig{},
|
|
||||||
"a0",
|
|
||||||
)
|
|
||||||
|
|
||||||
err = client.ContainerRemove(ctx, bID, types.ContainerRemoveOptions{Force: true})
|
err = client.ContainerRemove(ctx, bID, types.ContainerRemoveOptions{Force: true})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
bID = runContainer(ctx, t, client,
|
bID = runSimpleContainer(ctx, t, client, "b0", func(config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig) {
|
||||||
cntConfig,
|
hostConfig.Links = []string{"a0"}
|
||||||
&container.HostConfig{
|
})
|
||||||
Links: []string{"a0"},
|
|
||||||
},
|
|
||||||
&network.NetworkingConfig{},
|
|
||||||
"b0",
|
|
||||||
)
|
|
||||||
|
|
||||||
cntJSON, err = client.ContainerInspect(ctx, bID)
|
inspect, err := client.ContainerInspect(ctx, bID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, []string{"/a0:/b0/a0"}, cntJSON.HostConfig.Links)
|
assert.Equal(t, []string{"/a0:/b0/a0"}, inspect.HostConfig.Links)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue