Add unit tests for build no cache

This commit is contained in:
Michael Crosby 2013-08-02 19:12:38 +00:00
parent 3a123bc479
commit b9f0695924

View file

@ -195,21 +195,23 @@ func mkTestingFileServer(files [][2]string) (*httptest.Server, error) {
func TestBuild(t *testing.T) {
for _, ctx := range testContexts {
buildImage(ctx, t)
buildImage(ctx, t, nil, true)
}
}
func buildImage(context testContextTemplate, t *testing.T) *Image {
runtime, err := newTestRuntime()
if err != nil {
t.Fatal(err)
}
defer nuke(runtime)
func buildImage(context testContextTemplate, t *testing.T, srv *Server, useCache bool) *Image {
if srv == nil {
runtime, err := newTestRuntime()
if err != nil {
t.Fatal(err)
}
defer nuke(runtime)
srv := &Server{
runtime: runtime,
pullingPool: make(map[string]struct{}),
pushingPool: make(map[string]struct{}),
srv = &Server{
runtime: runtime,
pullingPool: make(map[string]struct{}),
pushingPool: make(map[string]struct{}),
}
}
httpServer, err := mkTestingFileServer(context.remoteFiles)
@ -224,10 +226,10 @@ func buildImage(context testContextTemplate, t *testing.T) *Image {
}
port := httpServer.URL[idx+1:]
ip := runtime.networkManager.bridgeNetwork.IP
ip := srv.runtime.networkManager.bridgeNetwork.IP
dockerfile := constructDockerfile(context.dockerfile, ip, port)
buildfile := NewBuildFile(srv, ioutil.Discard, false, true)
buildfile := NewBuildFile(srv, ioutil.Discard, false, useCache)
id, err := buildfile.Build(mkTestContext(dockerfile, context.files, t))
if err != nil {
t.Fatal(err)
@ -245,7 +247,7 @@ func TestVolume(t *testing.T) {
from {IMAGE}
volume /test
cmd Hello world
`, nil, nil}, t)
`, nil, nil}, t, nil, true)
if len(img.Config.Volumes) == 0 {
t.Fail()
@ -261,7 +263,7 @@ func TestBuildMaintainer(t *testing.T) {
img := buildImage(testContextTemplate{`
from {IMAGE}
maintainer dockerio
`, nil, nil}, t)
`, nil, nil}, t, nil, true)
if img.Author != "dockerio" {
t.Fail()
@ -273,7 +275,7 @@ func TestBuildEnv(t *testing.T) {
from {IMAGE}
env port 4243
`,
nil, nil}, t)
nil, nil}, t, nil, true)
hasEnv := false
for _, envVar := range img.Config.Env {
if envVar == "port=4243" {
@ -291,7 +293,7 @@ func TestBuildCmd(t *testing.T) {
from {IMAGE}
cmd ["/bin/echo", "Hello World"]
`,
nil, nil}, t)
nil, nil}, t, nil, true)
if img.Config.Cmd[0] != "/bin/echo" {
t.Log(img.Config.Cmd[0])
@ -308,7 +310,7 @@ func TestBuildExpose(t *testing.T) {
from {IMAGE}
expose 4243
`,
nil, nil}, t)
nil, nil}, t, nil, true)
if img.Config.PortSpecs[0] != "4243" {
t.Fail()
@ -320,8 +322,70 @@ func TestBuildEntrypoint(t *testing.T) {
from {IMAGE}
entrypoint ["/bin/echo"]
`,
nil, nil}, t)
nil, nil}, t, nil, true)
if img.Config.Entrypoint[0] != "/bin/echo" {
}
}
func TestBuildImageWithCache(t *testing.T) {
runtime, err := newTestRuntime()
if err != nil {
t.Fatal(err)
}
defer nuke(runtime)
srv := &Server{
runtime: runtime,
pullingPool: make(map[string]struct{}),
pushingPool: make(map[string]struct{}),
}
template := testContextTemplate{`
from {IMAGE}
maintainer dockerio
`,
nil, nil}
img := buildImage(template, t, srv, true)
imageId := img.ID
img = nil
img = buildImage(template, t, srv, true)
if imageId != img.ID {
t.Logf("Image ids should match: %s != %s", imageId, img.ID)
t.Fail()
}
}
func TestBuildImageWithoutCache(t *testing.T) {
runtime, err := newTestRuntime()
if err != nil {
t.Fatal(err)
}
defer nuke(runtime)
srv := &Server{
runtime: runtime,
pullingPool: make(map[string]struct{}),
pushingPool: make(map[string]struct{}),
}
template := testContextTemplate{`
from {IMAGE}
maintainer dockerio
`,
nil, nil}
img := buildImage(template, t, srv, true)
imageId := img.ID
img = nil
img = buildImage(template, t, srv, false)
if imageId == img.ID {
t.Logf("Image ids should not match: %s == %s", imageId, img.ID)
t.Fail()
}
}