12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 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}
- config, _, err := ParseRun([]string{GetTestImage(runtime).Id, "echo test"}, nil)
- if err != nil {
- t.Fatal(err)
- }
- id, err := srv.ContainerCreate(config)
- 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}
- config, _, err := ParseRun([]string{GetTestImage(runtime).Id, "/bin/cat"}, nil)
- if err != nil {
- t.Fatal(err)
- }
- id, err := srv.ContainerCreate(config)
- 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)
- }
- // FIXME: this failed once with a race condition ("Unable to remove filesystem for xxx: directory not empty")
- 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()))
- }
- }
|