1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add testcases for ADD caching, closes #880.

This commit is contained in:
Graydon Hoare 2013-12-12 05:33:15 +00:00 committed by Graydon Hoare
parent 3f9416b58d
commit 15a6854119

View file

@ -425,16 +425,10 @@ func TestBuildEntrypointRunCleanup(t *testing.T) {
} }
} }
func TestBuildImageWithCache(t *testing.T) { func checkCacheBehavior(t *testing.T, template testContextTemplate, expectHit bool) {
eng := NewTestEngine(t) eng := NewTestEngine(t)
defer nuke(mkRuntimeFromEngine(eng, t)) defer nuke(mkRuntimeFromEngine(eng, t))
template := testContextTemplate{`
from {IMAGE}
maintainer dockerio
`,
nil, nil}
img, err := buildImage(template, t, eng, true) img, err := buildImage(template, t, eng, true)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -443,43 +437,115 @@ func TestBuildImageWithCache(t *testing.T) {
imageId := img.ID imageId := img.ID
img = nil img = nil
img, err = buildImage(template, t, eng, true) img, err = buildImage(template, t, eng, expectHit)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if imageId != img.ID { hit := imageId == img.ID
t.Logf("Image ids should match: %s != %s", imageId, img.ID) if hit != expectHit {
t.Logf("Cache misbehavior, got hit=%t, expected hit=%t: (first: %s, second %s)",
hit, expectHit, imageId, img.ID)
t.Fail() t.Fail()
} }
} }
func TestBuildImageWithoutCache(t *testing.T) { func TestBuildImageWithCache(t *testing.T) {
eng := NewTestEngine(t)
defer nuke(mkRuntimeFromEngine(eng, t))
template := testContextTemplate{` template := testContextTemplate{`
from {IMAGE} from {IMAGE}
maintainer dockerio maintainer dockerio
`, `,
nil, nil} nil, nil}
checkCacheBehavior(t, template, true)
}
img, err := buildImage(template, t, eng, true) func TestBuildImageWithoutCache(t *testing.T) {
if err != nil { template := testContextTemplate{`
t.Fatal(err) from {IMAGE}
} maintainer dockerio
imageId := img.ID `,
nil, nil}
checkCacheBehavior(t, template, false)
}
img = nil func TestBuildADDLocalFileWithCache(t *testing.T) {
img, err = buildImage(template, t, eng, false) template := testContextTemplate{`
if err != nil { from {IMAGE}
t.Fatal(err) maintainer dockerio
} run echo "first"
add foo /usr/lib/bla/bar
run echo "second"
`,
[][2]string{{"foo", "hello"}},
nil}
checkCacheBehavior(t, template, true)
}
if imageId == img.ID { func TestBuildADDLocalFileWithoutCache(t *testing.T) {
t.Logf("Image ids should not match: %s == %s", imageId, img.ID) template := testContextTemplate{`
t.Fail() from {IMAGE}
} maintainer dockerio
run echo "first"
add foo /usr/lib/bla/bar
run echo "second"
`,
[][2]string{{"foo", "hello"}},
nil}
checkCacheBehavior(t, template, false)
}
func TestBuildADDRemoteFileWithCache(t *testing.T) {
template := testContextTemplate{`
from {IMAGE}
maintainer dockerio
run echo "first"
add http://{SERVERADDR}/baz /usr/lib/baz/quux
run echo "second"
`,
nil,
[][2]string{{"/baz", "world!"}}}
checkCacheBehavior(t, template, true)
}
func TestBuildADDRemoteFileWithoutCache(t *testing.T) {
template := testContextTemplate{`
from {IMAGE}
maintainer dockerio
run echo "first"
add http://{SERVERADDR}/baz /usr/lib/baz/quux
run echo "second"
`,
nil,
[][2]string{{"/baz", "world!"}}}
checkCacheBehavior(t, template, false)
}
func TestBuildADDLocalAndRemoteFilesWithCache(t *testing.T) {
template := testContextTemplate{`
from {IMAGE}
maintainer dockerio
run echo "first"
add foo /usr/lib/bla/bar
add http://{SERVERADDR}/baz /usr/lib/baz/quux
run echo "second"
`,
[][2]string{{"foo", "hello"}},
[][2]string{{"/baz", "world!"}}}
checkCacheBehavior(t, template, true)
}
func TestBuildADDLocalAndRemoteFilesWithoutCache(t *testing.T) {
template := testContextTemplate{`
from {IMAGE}
maintainer dockerio
run echo "first"
add foo /usr/lib/bla/bar
add http://{SERVERADDR}/baz /usr/lib/baz/quux
run echo "second"
`,
[][2]string{{"foo", "hello"}},
[][2]string{{"/baz", "world!"}}}
checkCacheBehavior(t, template, false)
} }
func TestForbiddenContextPath(t *testing.T) { func TestForbiddenContextPath(t *testing.T) {