Browse code

Readd build tests

Guillaume J. Charmes authored on 2013/05/29 07:31:06
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,72 @@
0
+package docker
1
+
2
+import (
3
+	"github.com/dotcloud/docker/utils"
4
+	"strings"
5
+	"testing"
6
+)
7
+
8
+const Dockerfile = `
9
+# VERSION		0.1
10
+# DOCKER-VERSION	0.2
11
+
12
+from   ` + unitTestImageName + `
13
+run    sh -c 'echo root:testpass > /tmp/passwd'
14
+run    mkdir -p /var/run/sshd
15
+`
16
+
17
+func TestBuild(t *testing.T) {
18
+	runtime, err := newTestRuntime()
19
+	if err != nil {
20
+		t.Fatal(err)
21
+	}
22
+	defer nuke(runtime)
23
+
24
+	srv := &Server{runtime: runtime}
25
+
26
+	buildfile := NewBuildFile(srv, &utils.NopWriter{})
27
+
28
+	imgId, err := buildfile.Build(strings.NewReader(Dockerfile), nil)
29
+	if err != nil {
30
+		t.Fatal(err)
31
+	}
32
+
33
+	builder := NewBuilder(runtime)
34
+	container, err := builder.Create(
35
+		&Config{
36
+			Image: imgId,
37
+			Cmd:   []string{"cat", "/tmp/passwd"},
38
+		},
39
+	)
40
+	if err != nil {
41
+		t.Fatal(err)
42
+	}
43
+	defer runtime.Destroy(container)
44
+
45
+	output, err := container.Output()
46
+	if err != nil {
47
+		t.Fatal(err)
48
+	}
49
+	if string(output) != "root:testpass\n" {
50
+		t.Fatalf("Unexpected output. Read '%s', expected '%s'", output, "root:testpass\n")
51
+	}
52
+
53
+	container2, err := builder.Create(
54
+		&Config{
55
+			Image: imgId,
56
+			Cmd:   []string{"ls", "-d", "/var/run/sshd"},
57
+		},
58
+	)
59
+	if err != nil {
60
+		t.Fatal(err)
61
+	}
62
+	defer runtime.Destroy(container2)
63
+
64
+	output, err = container2.Output()
65
+	if err != nil {
66
+		t.Fatal(err)
67
+	}
68
+	if string(output) != "/var/run/sshd\n" {
69
+		t.Fatal("/var/run/sshd has not been created")
70
+	}
71
+}
... ...
@@ -8,7 +8,6 @@ import (
8 8
 	"io/ioutil"
9 9
 	"net"
10 10
 	"os"
11
-	"os/exec"
12 11
 	"os/user"
13 12
 	"sync"
14 13
 	"testing"