Signed-off-by: Catalin Pirvu <pirvu.catalin94@gmail.com>
Catalin Pirvu authored on 2018/03/26 02:19:50... | ... |
@@ -6,6 +6,7 @@ import ( |
6 | 6 |
"time" |
7 | 7 |
|
8 | 8 |
"github.com/docker/docker/api/types" |
9 |
+ containertypes "github.com/docker/docker/api/types/container" |
|
9 | 10 |
"github.com/docker/docker/api/types/network" |
10 | 11 |
"github.com/docker/docker/integration/internal/container" |
11 | 12 |
"github.com/docker/docker/integration/internal/request" |
... | ... |
@@ -26,22 +27,24 @@ func TestRenameLinkedContainer(t *testing.T) { |
26 | 26 |
ctx := context.Background() |
27 | 27 |
client := request.NewAPIClient(t) |
28 | 28 |
|
29 |
- aID := container.Run(t, ctx, client, container.WithName("a0")) |
|
30 |
- bID := container.Run(t, ctx, client, container.WithName("b0"), container.WithLinks("a0")) |
|
29 |
+ aName := "a0" + t.Name() |
|
30 |
+ bName := "b0" + t.Name() |
|
31 |
+ aID := container.Run(t, ctx, client, container.WithName(aName)) |
|
32 |
+ bID := container.Run(t, ctx, client, container.WithName(bName), container.WithLinks(aName)) |
|
31 | 33 |
|
32 |
- err := client.ContainerRename(ctx, aID, "a1") |
|
34 |
+ err := client.ContainerRename(ctx, aID, "a1"+t.Name()) |
|
33 | 35 |
assert.NilError(t, err) |
34 | 36 |
|
35 |
- container.Run(t, ctx, client, container.WithName("a0")) |
|
37 |
+ container.Run(t, ctx, client, container.WithName(aName)) |
|
36 | 38 |
|
37 | 39 |
err = client.ContainerRemove(ctx, bID, types.ContainerRemoveOptions{Force: true}) |
38 | 40 |
assert.NilError(t, err) |
39 | 41 |
|
40 |
- bID = container.Run(t, ctx, client, container.WithName("b0"), container.WithLinks("a0")) |
|
42 |
+ bID = container.Run(t, ctx, client, container.WithName(bName), container.WithLinks(aName)) |
|
41 | 43 |
|
42 | 44 |
inspect, err := client.ContainerInspect(ctx, bID) |
43 | 45 |
assert.NilError(t, err) |
44 |
- assert.Check(t, is.DeepEqual([]string{"/a0:/b0/a0"}, inspect.HostConfig.Links)) |
|
46 |
+ assert.Check(t, is.DeepEqual([]string{"/" + aName + ":/" + bName + "/" + aName}, inspect.HostConfig.Links)) |
|
45 | 47 |
} |
46 | 48 |
|
47 | 49 |
func TestRenameStoppedContainer(t *testing.T) { |
... | ... |
@@ -49,7 +52,7 @@ func TestRenameStoppedContainer(t *testing.T) { |
49 | 49 |
ctx := context.Background() |
50 | 50 |
client := request.NewAPIClient(t) |
51 | 51 |
|
52 |
- oldName := "first_name" |
|
52 |
+ oldName := "first_name" + t.Name() |
|
53 | 53 |
cID := container.Run(t, ctx, client, container.WithName(oldName), container.WithCmd("sh")) |
54 | 54 |
poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond)) |
55 | 55 |
|
... | ... |
@@ -71,7 +74,7 @@ func TestRenameRunningContainerAndReuse(t *testing.T) { |
71 | 71 |
ctx := context.Background() |
72 | 72 |
client := request.NewAPIClient(t) |
73 | 73 |
|
74 |
- oldName := "first_name" |
|
74 |
+ oldName := "first_name" + t.Name() |
|
75 | 75 |
cID := container.Run(t, ctx, client, container.WithName(oldName)) |
76 | 76 |
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) |
77 | 77 |
|
... | ... |
@@ -99,7 +102,7 @@ func TestRenameInvalidName(t *testing.T) { |
99 | 99 |
ctx := context.Background() |
100 | 100 |
client := request.NewAPIClient(t) |
101 | 101 |
|
102 |
- oldName := "first_name" |
|
102 |
+ oldName := "first_name" + t.Name() |
|
103 | 103 |
cID := container.Run(t, ctx, client, container.WithName(oldName)) |
104 | 104 |
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) |
105 | 105 |
|
... | ... |
@@ -123,21 +126,25 @@ func TestRenameAnonymousContainer(t *testing.T) { |
123 | 123 |
ctx := context.Background() |
124 | 124 |
client := request.NewAPIClient(t) |
125 | 125 |
|
126 |
- _, err := client.NetworkCreate(ctx, "network1", types.NetworkCreate{}) |
|
126 |
+ networkName := "network1" + t.Name() |
|
127 |
+ _, err := client.NetworkCreate(ctx, networkName, types.NetworkCreate{}) |
|
128 |
+ |
|
127 | 129 |
assert.NilError(t, err) |
128 | 130 |
cID := container.Run(t, ctx, client, func(c *container.TestContainerConfig) { |
129 | 131 |
c.NetworkingConfig.EndpointsConfig = map[string]*network.EndpointSettings{ |
130 |
- "network1": {}, |
|
132 |
+ networkName: {}, |
|
131 | 133 |
} |
132 |
- c.HostConfig.NetworkMode = "network1" |
|
134 |
+ c.HostConfig.NetworkMode = containertypes.NetworkMode(networkName) |
|
133 | 135 |
}) |
134 |
- err = client.ContainerRename(ctx, cID, "container1") |
|
136 |
+ |
|
137 |
+ container1Name := "container1" + t.Name() |
|
138 |
+ err = client.ContainerRename(ctx, cID, container1Name) |
|
135 | 139 |
assert.NilError(t, err) |
136 | 140 |
// Stop/Start the container to get registered |
137 | 141 |
// FIXME(vdemeester) this is a really weird behavior as it fails otherwise |
138 |
- err = client.ContainerStop(ctx, "container1", nil) |
|
142 |
+ err = client.ContainerStop(ctx, container1Name, nil) |
|
139 | 143 |
assert.NilError(t, err) |
140 |
- err = client.ContainerStart(ctx, "container1", types.ContainerStartOptions{}) |
|
144 |
+ err = client.ContainerStart(ctx, container1Name, types.ContainerStartOptions{}) |
|
141 | 145 |
assert.NilError(t, err) |
142 | 146 |
|
143 | 147 |
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) |
... | ... |
@@ -148,10 +155,10 @@ func TestRenameAnonymousContainer(t *testing.T) { |
148 | 148 |
} |
149 | 149 |
cID = container.Run(t, ctx, client, func(c *container.TestContainerConfig) { |
150 | 150 |
c.NetworkingConfig.EndpointsConfig = map[string]*network.EndpointSettings{ |
151 |
- "network1": {}, |
|
151 |
+ networkName: {}, |
|
152 | 152 |
} |
153 |
- c.HostConfig.NetworkMode = "network1" |
|
154 |
- }, container.WithCmd("ping", count, "1", "container1")) |
|
153 |
+ c.HostConfig.NetworkMode = containertypes.NetworkMode(networkName) |
|
154 |
+ }, container.WithCmd("ping", count, "1", container1Name)) |
|
155 | 155 |
poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond)) |
156 | 156 |
|
157 | 157 |
inspect, err := client.ContainerInspect(ctx, cID) |
... | ... |
@@ -165,11 +172,13 @@ func TestRenameContainerWithSameName(t *testing.T) { |
165 | 165 |
ctx := context.Background() |
166 | 166 |
client := request.NewAPIClient(t) |
167 | 167 |
|
168 |
- cID := container.Run(t, ctx, client, container.WithName("old")) |
|
168 |
+ oldName := "old" + t.Name() |
|
169 |
+ cID := container.Run(t, ctx, client, container.WithName(oldName)) |
|
170 |
+ |
|
169 | 171 |
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) |
170 |
- err := client.ContainerRename(ctx, "old", "old") |
|
172 |
+ err := client.ContainerRename(ctx, oldName, oldName) |
|
171 | 173 |
testutil.ErrorContains(t, err, "Renaming a container with the same name") |
172 |
- err = client.ContainerRename(ctx, cID, "old") |
|
174 |
+ err = client.ContainerRename(ctx, cID, oldName) |
|
173 | 175 |
testutil.ErrorContains(t, err, "Renaming a container with the same name") |
174 | 176 |
} |
175 | 177 |
|
... | ... |
@@ -185,16 +194,19 @@ func TestRenameContainerWithLinkedContainer(t *testing.T) { |
185 | 185 |
ctx := context.Background() |
186 | 186 |
client := request.NewAPIClient(t) |
187 | 187 |
|
188 |
- db1ID := container.Run(t, ctx, client, container.WithName("db1")) |
|
188 |
+ db1Name := "db1" + t.Name() |
|
189 |
+ db1ID := container.Run(t, ctx, client, container.WithName(db1Name)) |
|
189 | 190 |
poll.WaitOn(t, container.IsInState(ctx, client, db1ID, "running"), poll.WithDelay(100*time.Millisecond)) |
190 | 191 |
|
191 |
- app1ID := container.Run(t, ctx, client, container.WithName("app1"), container.WithLinks("db1:/mysql")) |
|
192 |
+ app1Name := "app1" + t.Name() |
|
193 |
+ app2Name := "app2" + t.Name() |
|
194 |
+ app1ID := container.Run(t, ctx, client, container.WithName(app1Name), container.WithLinks(db1Name+":/mysql")) |
|
192 | 195 |
poll.WaitOn(t, container.IsInState(ctx, client, app1ID, "running"), poll.WithDelay(100*time.Millisecond)) |
193 | 196 |
|
194 |
- err := client.ContainerRename(ctx, "app1", "app2") |
|
197 |
+ err := client.ContainerRename(ctx, app1Name, app2Name) |
|
195 | 198 |
assert.NilError(t, err) |
196 | 199 |
|
197 |
- inspect, err := client.ContainerInspect(ctx, "app2/mysql") |
|
200 |
+ inspect, err := client.ContainerInspect(ctx, app2Name+"/mysql") |
|
198 | 201 |
assert.NilError(t, err) |
199 | 202 |
assert.Check(t, is.Equal(db1ID, inspect.ID)) |
200 | 203 |
} |