From 5b33b2463a27aa3356a4b6200cf4b81dd83c26a0 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 15:31:06 -0700 Subject: [PATCH] Readd build tests --- buildfile_test.go | 72 +++++++++++++++++++++++++++++++++++++++++++++++ runtime_test.go | 1 - 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 buildfile_test.go diff --git a/buildfile_test.go b/buildfile_test.go new file mode 100644 index 0000000000..b6f4e62ae9 --- /dev/null +++ b/buildfile_test.go @@ -0,0 +1,72 @@ +package docker + +import ( + "github.com/dotcloud/docker/utils" + "strings" + "testing" +) + +const Dockerfile = ` +# VERSION 0.1 +# DOCKER-VERSION 0.2 + +from ` + unitTestImageName + ` +run sh -c 'echo root:testpass > /tmp/passwd' +run mkdir -p /var/run/sshd +` + +func TestBuild(t *testing.T) { + runtime, err := newTestRuntime() + if err != nil { + t.Fatal(err) + } + defer nuke(runtime) + + srv := &Server{runtime: runtime} + + buildfile := NewBuildFile(srv, &utils.NopWriter{}) + + imgId, err := buildfile.Build(strings.NewReader(Dockerfile), nil) + if err != nil { + t.Fatal(err) + } + + builder := NewBuilder(runtime) + container, err := builder.Create( + &Config{ + Image: imgId, + Cmd: []string{"cat", "/tmp/passwd"}, + }, + ) + if err != nil { + t.Fatal(err) + } + defer runtime.Destroy(container) + + output, err := container.Output() + if err != nil { + t.Fatal(err) + } + if string(output) != "root:testpass\n" { + t.Fatalf("Unexpected output. Read '%s', expected '%s'", output, "root:testpass\n") + } + + container2, err := builder.Create( + &Config{ + Image: imgId, + Cmd: []string{"ls", "-d", "/var/run/sshd"}, + }, + ) + if err != nil { + t.Fatal(err) + } + defer runtime.Destroy(container2) + + output, err = container2.Output() + if err != nil { + t.Fatal(err) + } + if string(output) != "/var/run/sshd\n" { + t.Fatal("/var/run/sshd has not been created") + } +} diff --git a/runtime_test.go b/runtime_test.go index 27db53a884..55671e12b6 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -8,7 +8,6 @@ import ( "io/ioutil" "net" "os" - "os/exec" "os/user" "sync" "testing"