2013-05-06 18:59:33 +04:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2013-05-15 17:11:39 +04:00
|
|
|
func TestContainerTagImageDelete(t *testing.T) {
|
|
|
|
runtime, err := newTestRuntime()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer nuke(runtime)
|
|
|
|
|
|
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
|
|
|
if err := srv.runtime.repositories.Set("utest", "tag1", unitTestImageName, false); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := srv.runtime.repositories.Set("utest/docker", "tag2", unitTestImageName, false); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
images, err := srv.Images(false, "")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(images) != 3 {
|
|
|
|
t.Errorf("Excepted 3 images, %d found", len(images))
|
|
|
|
}
|
|
|
|
|
2013-05-31 18:37:02 +04:00
|
|
|
if _, err := srv.ImageDelete("utest/docker:tag2", true); err != nil {
|
2013-05-15 17:11:39 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
images, err = srv.Images(false, "")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(images) != 2 {
|
|
|
|
t.Errorf("Excepted 2 images, %d found", len(images))
|
|
|
|
}
|
|
|
|
|
2013-05-31 18:37:02 +04:00
|
|
|
if _, err := srv.ImageDelete("utest:tag1", true); err != nil {
|
2013-05-15 17:11:39 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
images, err = srv.Images(false, "")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(images) != 1 {
|
|
|
|
t.Errorf("Excepted 1 image, %d found", len(images))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-06 18:59:33 +04:00
|
|
|
func TestCreateRm(t *testing.T) {
|
|
|
|
runtime, err := newTestRuntime()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer nuke(runtime)
|
|
|
|
|
|
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
2013-06-04 22:00:22 +04:00
|
|
|
config, _, err := ParseRun([]string{GetTestImage(runtime).ID, "echo test"}, nil)
|
2013-05-06 18:59:33 +04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-05-10 04:50:56 +04:00
|
|
|
id, err := srv.ContainerCreate(config)
|
2013-05-06 18:59:33 +04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(runtime.List()) != 1 {
|
|
|
|
t.Errorf("Expected 1 container, %v found", len(runtime.List()))
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = srv.ContainerDestroy(id, true); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(runtime.List()) != 0 {
|
|
|
|
t.Errorf("Expected 0 container, %v found", len(runtime.List()))
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateStartRestartStopStartKillRm(t *testing.T) {
|
|
|
|
runtime, err := newTestRuntime()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer nuke(runtime)
|
|
|
|
|
|
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
2013-06-04 22:00:22 +04:00
|
|
|
config, _, err := ParseRun([]string{GetTestImage(runtime).ID, "/bin/cat"}, nil)
|
2013-05-06 18:59:33 +04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-05-10 04:50:56 +04:00
|
|
|
id, err := srv.ContainerCreate(config)
|
2013-05-06 18:59:33 +04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(runtime.List()) != 1 {
|
|
|
|
t.Errorf("Expected 1 container, %v found", len(runtime.List()))
|
|
|
|
}
|
|
|
|
|
|
|
|
err = srv.ContainerStart(id)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = srv.ContainerRestart(id, 1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = srv.ContainerStop(id, 1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = srv.ContainerStart(id)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = srv.ContainerKill(id)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-05-25 05:31:47 +04:00
|
|
|
// FIXME: this failed once with a race condition ("Unable to remove filesystem for xxx: directory not empty")
|
2013-05-06 18:59:33 +04:00
|
|
|
if err = srv.ContainerDestroy(id, true); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(runtime.List()) != 0 {
|
|
|
|
t.Errorf("Expected 0 container, %v found", len(runtime.List()))
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|