Signed-off-by: Lei Jitang <leijitang@huawei.com>
| ... | ... |
@@ -314,6 +314,60 @@ func TestRunWithoutNetworking(t *testing.T) {
|
| 314 | 314 |
logDone("run - disable networking with -n=false")
|
| 315 | 315 |
} |
| 316 | 316 |
|
| 317 |
+//test --link use container name to link target |
|
| 318 |
+func TestRunLinksContainerWithContainerName(t *testing.T) {
|
|
| 319 |
+ cmd := exec.Command(dockerBinary, "run", "-t", "-d", "--name", "parent", "busybox") |
|
| 320 |
+ out, _, _, err := runCommandWithStdoutStderr(cmd) |
|
| 321 |
+ if err != nil {
|
|
| 322 |
+ t.Fatal("failed to run container: %v, output: %q", err, out)
|
|
| 323 |
+ } |
|
| 324 |
+ cmd = exec.Command(dockerBinary, "inspect", "-f", "{{.NetworkSettings.IPAddress}}", "parent")
|
|
| 325 |
+ ip, _, _, err := runCommandWithStdoutStderr(cmd) |
|
| 326 |
+ if err != nil {
|
|
| 327 |
+ t.Fatal("failed to inspect container: %v, output: %q", err, ip)
|
|
| 328 |
+ } |
|
| 329 |
+ ip = strings.TrimSpace(ip) |
|
| 330 |
+ cmd = exec.Command(dockerBinary, "run", "--link", "parent:test", "busybox", "/bin/cat", "/etc/hosts") |
|
| 331 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 332 |
+ if err != nil {
|
|
| 333 |
+ t.Fatal("failed to run container: %v, output: %q", err, out)
|
|
| 334 |
+ } |
|
| 335 |
+ if !strings.Contains(out, ip+" test") {
|
|
| 336 |
+ t.Fatalf("use a container name to link target failed")
|
|
| 337 |
+ } |
|
| 338 |
+ deleteAllContainers() |
|
| 339 |
+ |
|
| 340 |
+ logDone("run - use a container name to link target work")
|
|
| 341 |
+} |
|
| 342 |
+ |
|
| 343 |
+//test --link use container id to link target |
|
| 344 |
+func TestRunLinksContainerWithContainerId(t *testing.T) {
|
|
| 345 |
+ cmd := exec.Command(dockerBinary, "run", "-t", "-d", "busybox") |
|
| 346 |
+ cID, _, _, err := runCommandWithStdoutStderr(cmd) |
|
| 347 |
+ if err != nil {
|
|
| 348 |
+ t.Fatal("failed to run container: %v, output: %q", err, cID)
|
|
| 349 |
+ } |
|
| 350 |
+ cID = strings.TrimSpace(cID) |
|
| 351 |
+ cmd = exec.Command(dockerBinary, "inspect", "-f", "{{.NetworkSettings.IPAddress}}", cID)
|
|
| 352 |
+ ip, _, _, err := runCommandWithStdoutStderr(cmd) |
|
| 353 |
+ if err != nil {
|
|
| 354 |
+ t.Fatal("faild to inspect container: %v, output: %q", err, ip)
|
|
| 355 |
+ } |
|
| 356 |
+ ip = strings.TrimSpace(ip) |
|
| 357 |
+ cmd = exec.Command(dockerBinary, "run", "--link", cID+":test", "busybox", "/bin/cat", "/etc/hosts") |
|
| 358 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 359 |
+ if err != nil {
|
|
| 360 |
+ t.Fatal("failed to run container: %v, output: %q", err, out)
|
|
| 361 |
+ } |
|
| 362 |
+ if !strings.Contains(out, ip+" test") {
|
|
| 363 |
+ t.Fatalf("use a container id to link target failed")
|
|
| 364 |
+ } |
|
| 365 |
+ |
|
| 366 |
+ deleteAllContainers() |
|
| 367 |
+ |
|
| 368 |
+ logDone("run - use a container id to link target work")
|
|
| 369 |
+} |
|
| 370 |
+ |
|
| 317 | 371 |
// Regression test for #4741 |
| 318 | 372 |
func TestRunWithVolumesAsFiles(t *testing.T) {
|
| 319 | 373 |
runCmd := exec.Command(dockerBinary, "run", "--name", "test-data", "--volume", "/etc/hosts:/target-file", "busybox", "true") |