Add build UT

This commit is contained in:
Guillaume J. Charmes 2013-06-13 18:52:41 -07:00
parent f03ebc20aa
commit 2f14dae83f
1 changed files with 38 additions and 3 deletions

View File

@ -11,8 +11,13 @@ const Dockerfile = `
# DOCKER-VERSION 0.2 # DOCKER-VERSION 0.2
from ` + unitTestImageName + ` from ` + unitTestImageName + `
maintainer docker
expose 22
env FOO BAR
cmd ["echo", "hello", "world"]
run sh -c 'echo root:testpass > /tmp/passwd' run sh -c 'echo root:testpass > /tmp/passwd'
run mkdir -p /var/run/sshd run mkdir -p /var/run/sshd
add . /src
` `
const DockerfileNoNewLine = ` const DockerfileNoNewLine = `
@ -20,10 +25,15 @@ const DockerfileNoNewLine = `
# DOCKER-VERSION 0.2 # DOCKER-VERSION 0.2
from ` + unitTestImageName + ` from ` + unitTestImageName + `
maintainer docker
expose 22
env FOO BAR
cmd ["echo", "hello", "world"]
run sh -c 'echo root:testpass > /tmp/passwd' run sh -c 'echo root:testpass > /tmp/passwd'
run mkdir -p /var/run/sshd` run mkdir -p /var/run/sshd
add . /src`
func TestBuild(t *testing.T) { func TestBuildFile(t *testing.T) {
dockerfiles := []string{Dockerfile, DockerfileNoNewLine} dockerfiles := []string{Dockerfile, DockerfileNoNewLine}
for _, Dockerfile := range dockerfiles { for _, Dockerfile := range dockerfiles {
runtime, err := newTestRuntime() runtime, err := newTestRuntime()
@ -36,7 +46,12 @@ func TestBuild(t *testing.T) {
buildfile := NewBuildFile(srv, &utils.NopWriter{}) buildfile := NewBuildFile(srv, &utils.NopWriter{})
imgID, err := buildfile.Build(strings.NewReader(Dockerfile), nil) context, err := fakeTar()
if err != nil {
t.Fatal(err)
}
imgID, err := buildfile.Build(strings.NewReader(Dockerfile), context)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -79,5 +94,25 @@ func TestBuild(t *testing.T) {
if string(output) != "/var/run/sshd\n" { if string(output) != "/var/run/sshd\n" {
t.Fatal("/var/run/sshd has not been created") t.Fatal("/var/run/sshd has not been created")
} }
container3, err := builder.Create(
&Config{
Image: imgID,
Cmd: []string{"ls", "/src"},
},
)
if err != nil {
t.Fatal(err)
}
defer runtime.Destroy(container3)
output, err = container3.Output()
if err != nil {
t.Fatal(err)
}
if string(output) != "etc\nvar\n" {
t.Fatalf("Unexpected output. Expected: '%s', received: '%s'", "etc\nvar\n", string(output))
}
} }
} }