add TestContainerOrphaning integration test

This commit is contained in:
Gabriel Monroy 2013-12-20 16:52:34 -07:00
parent aa619de748
commit c995c9bb91
1 changed files with 63 additions and 0 deletions

View File

@ -968,3 +968,66 @@ func TestRunCidFile(t *testing.T) {
})
}
func TestContainerOrphaning(t *testing.T) {
// setup a temporary directory
tmpDir, err := ioutil.TempDir("", "project")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpDir)
// setup a CLI and server
cli := docker.NewDockerCli(nil, os.Stdout, ioutil.Discard, testDaemonProto, testDaemonAddr)
defer cleanup(globalEngine, t)
srv := mkServerFromEngine(globalEngine, t)
// closure to build something
buildSomething := func(template string, image string) string {
dockerfile := path.Join(tmpDir, "Dockerfile")
replacer := strings.NewReplacer("{IMAGE}", unitTestImageID)
contents := replacer.Replace(template)
ioutil.WriteFile(dockerfile, []byte(contents), 0x777)
if err := cli.CmdBuild("-t", image, tmpDir); err != nil {
t.Fatal(err)
}
img, err := srv.ImageInspect(image)
if err != nil {
t.Fatal(err)
}
return img.ID
}
// build an image
imageName := "orphan-test"
template1 := `
from {IMAGE}
cmd ["/bin/echo", "holla"]
`
img1 := buildSomething(template1, imageName)
// create a container using the fist image
if err := cli.CmdRun(imageName); err != nil {
t.Fatal(err)
}
// build a new image that splits lineage
template2 := `
from {IMAGE}
cmd ["/bin/echo", "holla"]
expose 22
`
buildSomething(template2, imageName)
// remove the second image by name
resp, err := srv.ImageDelete(imageName, true)
// see if we deleted the first image (and orphaned the container)
for _, i := range resp {
if img1 == i.Deleted {
t.Fatal("Orphaned image with container")
}
}
}