1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Use unique names for container/rename_test.go

Signed-off-by: Catalin Pirvu <pirvu.catalin94@gmail.com>
This commit is contained in:
Catalin Pirvu 2018-03-25 20:19:50 +03:00
parent 5f17312653
commit 90b514922b

View file

@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
containertypes "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/integration/internal/container" "github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/integration/internal/request" "github.com/docker/docker/integration/internal/request"
@ -26,22 +27,24 @@ func TestRenameLinkedContainer(t *testing.T) {
ctx := context.Background() ctx := context.Background()
client := request.NewAPIClient(t) client := request.NewAPIClient(t)
aID := container.Run(t, ctx, client, container.WithName("a0")) aName := "a0" + t.Name()
bID := container.Run(t, ctx, client, container.WithName("b0"), container.WithLinks("a0")) bName := "b0" + t.Name()
aID := container.Run(t, ctx, client, container.WithName(aName))
bID := container.Run(t, ctx, client, container.WithName(bName), container.WithLinks(aName))
err := client.ContainerRename(ctx, aID, "a1") err := client.ContainerRename(ctx, aID, "a1"+t.Name())
assert.NilError(t, err) assert.NilError(t, err)
container.Run(t, ctx, client, container.WithName("a0")) container.Run(t, ctx, client, container.WithName(aName))
err = client.ContainerRemove(ctx, bID, types.ContainerRemoveOptions{Force: true}) err = client.ContainerRemove(ctx, bID, types.ContainerRemoveOptions{Force: true})
assert.NilError(t, err) assert.NilError(t, err)
bID = container.Run(t, ctx, client, container.WithName("b0"), container.WithLinks("a0")) bID = container.Run(t, ctx, client, container.WithName(bName), container.WithLinks(aName))
inspect, err := client.ContainerInspect(ctx, bID) inspect, err := client.ContainerInspect(ctx, bID)
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual([]string{"/a0:/b0/a0"}, inspect.HostConfig.Links)) assert.Check(t, is.DeepEqual([]string{"/" + aName + ":/" + bName + "/" + aName}, inspect.HostConfig.Links))
} }
func TestRenameStoppedContainer(t *testing.T) { func TestRenameStoppedContainer(t *testing.T) {
@ -49,7 +52,7 @@ func TestRenameStoppedContainer(t *testing.T) {
ctx := context.Background() ctx := context.Background()
client := request.NewAPIClient(t) client := request.NewAPIClient(t)
oldName := "first_name" oldName := "first_name" + t.Name()
cID := container.Run(t, ctx, client, container.WithName(oldName), container.WithCmd("sh")) cID := container.Run(t, ctx, client, container.WithName(oldName), container.WithCmd("sh"))
poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond)) poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond))
@ -71,7 +74,7 @@ func TestRenameRunningContainerAndReuse(t *testing.T) {
ctx := context.Background() ctx := context.Background()
client := request.NewAPIClient(t) client := request.NewAPIClient(t)
oldName := "first_name" oldName := "first_name" + t.Name()
cID := container.Run(t, ctx, client, container.WithName(oldName)) cID := container.Run(t, ctx, client, container.WithName(oldName))
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
@ -99,7 +102,7 @@ func TestRenameInvalidName(t *testing.T) {
ctx := context.Background() ctx := context.Background()
client := request.NewAPIClient(t) client := request.NewAPIClient(t)
oldName := "first_name" oldName := "first_name" + t.Name()
cID := container.Run(t, ctx, client, container.WithName(oldName)) cID := container.Run(t, ctx, client, container.WithName(oldName))
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
@ -123,21 +126,25 @@ func TestRenameAnonymousContainer(t *testing.T) {
ctx := context.Background() ctx := context.Background()
client := request.NewAPIClient(t) client := request.NewAPIClient(t)
_, err := client.NetworkCreate(ctx, "network1", types.NetworkCreate{}) networkName := "network1" + t.Name()
_, err := client.NetworkCreate(ctx, networkName, types.NetworkCreate{})
assert.NilError(t, err) assert.NilError(t, err)
cID := container.Run(t, ctx, client, func(c *container.TestContainerConfig) { cID := container.Run(t, ctx, client, func(c *container.TestContainerConfig) {
c.NetworkingConfig.EndpointsConfig = map[string]*network.EndpointSettings{ c.NetworkingConfig.EndpointsConfig = map[string]*network.EndpointSettings{
"network1": {}, networkName: {},
} }
c.HostConfig.NetworkMode = "network1" c.HostConfig.NetworkMode = containertypes.NetworkMode(networkName)
}) })
err = client.ContainerRename(ctx, cID, "container1")
container1Name := "container1" + t.Name()
err = client.ContainerRename(ctx, cID, container1Name)
assert.NilError(t, err) assert.NilError(t, err)
// Stop/Start the container to get registered // Stop/Start the container to get registered
// FIXME(vdemeester) this is a really weird behavior as it fails otherwise // FIXME(vdemeester) this is a really weird behavior as it fails otherwise
err = client.ContainerStop(ctx, "container1", nil) err = client.ContainerStop(ctx, container1Name, nil)
assert.NilError(t, err) assert.NilError(t, err)
err = client.ContainerStart(ctx, "container1", types.ContainerStartOptions{}) err = client.ContainerStart(ctx, container1Name, types.ContainerStartOptions{})
assert.NilError(t, err) assert.NilError(t, err)
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
@ -148,10 +155,10 @@ func TestRenameAnonymousContainer(t *testing.T) {
} }
cID = container.Run(t, ctx, client, func(c *container.TestContainerConfig) { cID = container.Run(t, ctx, client, func(c *container.TestContainerConfig) {
c.NetworkingConfig.EndpointsConfig = map[string]*network.EndpointSettings{ c.NetworkingConfig.EndpointsConfig = map[string]*network.EndpointSettings{
"network1": {}, networkName: {},
} }
c.HostConfig.NetworkMode = "network1" c.HostConfig.NetworkMode = containertypes.NetworkMode(networkName)
}, container.WithCmd("ping", count, "1", "container1")) }, container.WithCmd("ping", count, "1", container1Name))
poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond)) poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond))
inspect, err := client.ContainerInspect(ctx, cID) inspect, err := client.ContainerInspect(ctx, cID)
@ -165,11 +172,13 @@ func TestRenameContainerWithSameName(t *testing.T) {
ctx := context.Background() ctx := context.Background()
client := request.NewAPIClient(t) client := request.NewAPIClient(t)
cID := container.Run(t, ctx, client, container.WithName("old")) oldName := "old" + t.Name()
cID := container.Run(t, ctx, client, container.WithName(oldName))
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
err := client.ContainerRename(ctx, "old", "old") err := client.ContainerRename(ctx, oldName, oldName)
testutil.ErrorContains(t, err, "Renaming a container with the same name") testutil.ErrorContains(t, err, "Renaming a container with the same name")
err = client.ContainerRename(ctx, cID, "old") err = client.ContainerRename(ctx, cID, oldName)
testutil.ErrorContains(t, err, "Renaming a container with the same name") testutil.ErrorContains(t, err, "Renaming a container with the same name")
} }
@ -185,16 +194,19 @@ func TestRenameContainerWithLinkedContainer(t *testing.T) {
ctx := context.Background() ctx := context.Background()
client := request.NewAPIClient(t) client := request.NewAPIClient(t)
db1ID := container.Run(t, ctx, client, container.WithName("db1")) db1Name := "db1" + t.Name()
db1ID := container.Run(t, ctx, client, container.WithName(db1Name))
poll.WaitOn(t, container.IsInState(ctx, client, db1ID, "running"), poll.WithDelay(100*time.Millisecond)) poll.WaitOn(t, container.IsInState(ctx, client, db1ID, "running"), poll.WithDelay(100*time.Millisecond))
app1ID := container.Run(t, ctx, client, container.WithName("app1"), container.WithLinks("db1:/mysql")) app1Name := "app1" + t.Name()
app2Name := "app2" + t.Name()
app1ID := container.Run(t, ctx, client, container.WithName(app1Name), container.WithLinks(db1Name+":/mysql"))
poll.WaitOn(t, container.IsInState(ctx, client, app1ID, "running"), poll.WithDelay(100*time.Millisecond)) poll.WaitOn(t, container.IsInState(ctx, client, app1ID, "running"), poll.WithDelay(100*time.Millisecond))
err := client.ContainerRename(ctx, "app1", "app2") err := client.ContainerRename(ctx, app1Name, app2Name)
assert.NilError(t, err) assert.NilError(t, err)
inspect, err := client.ContainerInspect(ctx, "app2/mysql") inspect, err := client.ContainerInspect(ctx, app2Name+"/mysql")
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(db1ID, inspect.ID)) assert.Check(t, is.Equal(db1ID, inspect.ID))
} }