Browse code

Fixes symlink, container size, and kmsg tests

Changes symlink, container size and kmsg tests to account for lxc driver.
Signed-off-by: Abin Shahab <ashahab@altiscale.com> (github: ashahab-altiscale)
Docker-DCO-1.1-Signed-off-by: Abin Shahab <ashahab@altiscale.com> (github: ashahab-altiscale)

Abin Shahab authored on 2015/01/23 21:17:05
Showing 3 changed files
... ...
@@ -89,10 +89,22 @@ func TestDiffEnsureOnlyKmsgAndPtmx(t *testing.T) {
89 89
 	deleteContainer(cleanCID)
90 90
 
91 91
 	expected := map[string]bool{
92
-		"C /dev":      true,
93
-		"A /dev/full": true, // busybox
94
-		"C /dev/ptmx": true, // libcontainer
95
-		"A /dev/kmsg": true, // lxc
92
+		"C /dev":         true,
93
+		"A /dev/full":    true, // busybox
94
+		"C /dev/ptmx":    true, // libcontainer
95
+		"A /dev/kmsg":    true, // lxc
96
+		"A /dev/fd":      true,
97
+		"A /dev/fuse":    true,
98
+		"A /dev/ptmx":    true,
99
+		"A /dev/null":    true,
100
+		"A /dev/random":  true,
101
+		"A /dev/stdout":  true,
102
+		"A /dev/stderr":  true,
103
+		"A /dev/tty1":    true,
104
+		"A /dev/stdin":   true,
105
+		"A /dev/tty":     true,
106
+		"A /dev/urandom": true,
107
+		"A /dev/zero":    true,
96 108
 	}
97 109
 
98 110
 	for _, line := range strings.Split(out, "\n") {
... ...
@@ -1,7 +1,9 @@
1 1
 package main
2 2
 
3 3
 import (
4
+	"fmt"
4 5
 	"os/exec"
6
+	"strconv"
5 7
 	"strings"
6 8
 	"testing"
7 9
 	"time"
... ...
@@ -243,6 +245,18 @@ func assertContainerList(out string, expected []string) bool {
243 243
 }
244 244
 
245 245
 func TestPsListContainersSize(t *testing.T) {
246
+	cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "hello")
247
+	runCommandWithOutput(cmd)
248
+	cmd = exec.Command(dockerBinary, "ps", "-s", "-n=1")
249
+	base_out, _, err := runCommandWithOutput(cmd)
250
+	base_lines := strings.Split(strings.Trim(base_out, "\n "), "\n")
251
+	base_sizeIndex := strings.Index(base_lines[0], "SIZE")
252
+	base_foundSize := base_lines[1][base_sizeIndex:]
253
+	base_bytes, err := strconv.Atoi(strings.Split(base_foundSize, " ")[0])
254
+	if err != nil {
255
+		t.Fatal(err)
256
+	}
257
+
246 258
 	name := "test_size"
247 259
 	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test")
248 260
 	out, _, err := runCommandWithOutput(runCmd)
... ...
@@ -275,7 +289,7 @@ func TestPsListContainersSize(t *testing.T) {
275 275
 	if foundID != id[:12] {
276 276
 		t.Fatalf("Expected id %s, got %s", id[:12], foundID)
277 277
 	}
278
-	expectedSize := "2 B"
278
+	expectedSize := fmt.Sprintf("%d B", (2 + base_bytes))
279 279
 	foundSize := lines[1][sizeIndex:]
280 280
 	if foundSize != expectedSize {
281 281
 		t.Fatalf("Expected size %q, got %q", expectedSize, foundSize)
... ...
@@ -572,14 +572,14 @@ func TestRunCreateVolume(t *testing.T) {
572 572
 func TestRunCreateVolumeWithSymlink(t *testing.T) {
573 573
 	buildCmd := exec.Command(dockerBinary, "build", "-t", "docker-test-createvolumewithsymlink", "-")
574 574
 	buildCmd.Stdin = strings.NewReader(`FROM busybox
575
-		RUN mkdir /foo && ln -s /foo /bar`)
575
+		RUN ln -s home /bar`)
576 576
 	buildCmd.Dir = workingDirectory
577 577
 	err := buildCmd.Run()
578 578
 	if err != nil {
579 579
 		t.Fatalf("could not build 'docker-test-createvolumewithsymlink': %v", err)
580 580
 	}
581 581
 
582
-	cmd := exec.Command(dockerBinary, "run", "-v", "/bar/foo", "--name", "test-createvolumewithsymlink", "docker-test-createvolumewithsymlink", "sh", "-c", "mount | grep -q /foo/foo")
582
+	cmd := exec.Command(dockerBinary, "run", "-v", "/bar/foo", "--name", "test-createvolumewithsymlink", "docker-test-createvolumewithsymlink", "sh", "-c", "mount | grep -q /home/foo")
583 583
 	exitCode, err := runCommand(cmd)
584 584
 	if err != nil || exitCode != 0 {
585 585
 		t.Fatalf("[run] err: %v, exitcode: %d", err, exitCode)
... ...
@@ -615,7 +615,7 @@ func TestRunVolumesFromSymlinkPath(t *testing.T) {
615 615
 	name := "docker-test-volumesfromsymlinkpath"
616 616
 	buildCmd := exec.Command(dockerBinary, "build", "-t", name, "-")
617 617
 	buildCmd.Stdin = strings.NewReader(`FROM busybox
618
-		RUN mkdir /baz && ln -s /baz /foo
618
+		RUN ln -s home /foo
619 619
 		VOLUME ["/foo/bar"]`)
620 620
 	buildCmd.Dir = workingDirectory
621 621
 	err := buildCmd.Run()