Browse code

Add a network test

This just tries pinging first 127.0.0.1 and then 8.8.8.8.

We can't ping via a dns name, because libresolv.so is missing
from the test image, so dns resolving doesn't work.

Alexander Larsson authored on 2013/09/18 17:53:00
Showing 1 changed files
... ...
@@ -407,6 +407,44 @@ func TestOutput(t *testing.T) {
407 407
 	}
408 408
 }
409 409
 
410
+func TestContainerNetwork(t *testing.T) {
411
+	runtime := mkRuntime(t)
412
+	defer nuke(runtime)
413
+	container, err := runtime.Create(
414
+		&Config{
415
+			Image: GetTestImage(runtime).ID,
416
+			Cmd:   []string{"ping", "-c", "1", "127.0.0.1"},
417
+		},
418
+	)
419
+	if err != nil {
420
+		t.Fatal(err)
421
+	}
422
+	defer runtime.Destroy(container)
423
+	if err := container.Run(); err != nil {
424
+		t.Fatal(err)
425
+	}
426
+	if container.State.ExitCode != 0 {
427
+		t.Errorf("Unexpected ping 127.0.0.1 exit code %d (expected 0)", container.State.ExitCode)
428
+	}
429
+
430
+	container, err = runtime.Create(
431
+		&Config{
432
+			Image: GetTestImage(runtime).ID,
433
+			Cmd:   []string{"ping", "-c", "1", "8.8.8.8"},
434
+		},
435
+	)
436
+	if err != nil {
437
+		t.Fatal(err)
438
+	}
439
+	defer runtime.Destroy(container)
440
+	if err := container.Run(); err != nil {
441
+		t.Fatal(err)
442
+	}
443
+	if container.State.ExitCode != 0 {
444
+		t.Errorf("Unexpected ping 8.8.8.8 exit code %d (expected 0)", container.State.ExitCode)
445
+	}
446
+}
447
+
410 448
 func TestKillDifferentUser(t *testing.T) {
411 449
 	runtime := mkRuntime(t)
412 450
 	defer nuke(runtime)