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

97 lines
1.6 KiB
Go
Raw Normal View History

2013-05-06 10:59:33 -04:00
package docker
import (
"testing"
)
func TestCreateRm(t *testing.T) {
runtime, err := newTestRuntime()
if err != nil {
t.Fatal(err)
}
defer nuke(runtime)
srv := &Server{runtime: runtime}
2013-05-07 14:37:35 -04:00
config, _, err := ParseRun([]string{GetTestImage(runtime).Id, "echo test"}, nil)
2013-05-06 10:59:33 -04:00
if err != nil {
t.Fatal(err)
}
id, err := srv.ContainerCreate(config)
2013-05-06 10: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-05-07 14:37:35 -04:00
config, _, err := ParseRun([]string{GetTestImage(runtime).Id, "/bin/cat"}, nil)
2013-05-06 10:59:33 -04:00
if err != nil {
t.Fatal(err)
}
id, err := srv.ContainerCreate(config)
2013-05-06 10: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)
}
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()))
}
}