|
@@ -12,7 +12,7 @@ import (
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
-func TestAuth(t *testing.T) {
|
|
|
|
|
|
+func TestGetAuth(t *testing.T) {
|
|
runtime, err := newTestRuntime()
|
|
runtime, err := newTestRuntime()
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
@@ -50,29 +50,39 @@ func TestAuth(t *testing.T) {
|
|
t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code)
|
|
t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code)
|
|
}
|
|
}
|
|
|
|
|
|
- authConfig = &auth.AuthConfig{}
|
|
|
|
|
|
+ if runtime.authConfig.Username != authConfig.Username ||
|
|
|
|
+ runtime.authConfig.Password != authConfig.Password ||
|
|
|
|
+ runtime.authConfig.Email != authConfig.Email {
|
|
|
|
+ t.Fatalf("The auth configuration hasn't been set correctly")
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
- req, err = http.NewRequest("GET", "/auth", nil)
|
|
|
|
|
|
+func TestGetVersion(t *testing.T) {
|
|
|
|
+ runtime, err := newTestRuntime()
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
+ defer nuke(runtime)
|
|
|
|
|
|
- body, err = getAuth(srv, nil, req, nil)
|
|
|
|
|
|
+ srv := &Server{runtime: runtime}
|
|
|
|
+
|
|
|
|
+ body, err := getVersion(srv, nil, nil, nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- err = json.Unmarshal(body, authConfig)
|
|
|
|
|
|
+ v := &ApiVersion{}
|
|
|
|
+
|
|
|
|
+ err = json.Unmarshal(body, v)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
-
|
|
|
|
- if authConfig.Username != "utest" {
|
|
|
|
- t.Errorf("Expected username to be utest, %s found", authConfig.Username)
|
|
|
|
|
|
+ if v.Version != VERSION {
|
|
|
|
+ t.Errorf("Excepted version %s, %s found", VERSION, v.Version)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func TestVersion(t *testing.T) {
|
|
|
|
|
|
+func TestGetInfo(t *testing.T) {
|
|
runtime, err := newTestRuntime()
|
|
runtime, err := newTestRuntime()
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
@@ -81,27 +91,21 @@ func TestVersion(t *testing.T) {
|
|
|
|
|
|
srv := &Server{runtime: runtime}
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
|
- body, err := getVersion(srv, nil, nil, nil)
|
|
|
|
|
|
+ body, err := getInfo(srv, nil, nil, nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
-
|
|
|
|
- v := &ApiVersion{}
|
|
|
|
-
|
|
|
|
- err = json.Unmarshal(body, v)
|
|
|
|
|
|
+ infos := &ApiInfo{}
|
|
|
|
+ err = json.Unmarshal(body, infos)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- if v.Version != VERSION {
|
|
|
|
- t.Errorf("Excepted version %s, %s found", VERSION, v.Version)
|
|
|
|
|
|
+ if infos.Version != VERSION {
|
|
|
|
+ t.Errorf("Excepted version %s, %s found", VERSION, infos.Version)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func TestContainersExport(t *testing.T) {
|
|
|
|
- //FIXME: Implement this test
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func TestGetImages(t *testing.T) {
|
|
|
|
|
|
+func TestGetImagesJson(t *testing.T) {
|
|
runtime, err := newTestRuntime()
|
|
runtime, err := newTestRuntime()
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
@@ -111,12 +115,12 @@ func TestGetImages(t *testing.T) {
|
|
srv := &Server{runtime: runtime}
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
|
// FIXME: Do more tests with filter
|
|
// FIXME: Do more tests with filter
|
|
- req, err := http.NewRequest("GET", "/images?quiet=0&all=0", nil)
|
|
|
|
|
|
+ req, err := http.NewRequest("GET", "/images/json?quiet=0&all=0", nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := getImages(srv, nil, req, nil)
|
|
|
|
|
|
+ body, err := getImagesJson(srv, nil, req, nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
@@ -136,7 +140,12 @@ func TestGetImages(t *testing.T) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func TestInfo(t *testing.T) {
|
|
|
|
|
|
+func TestGetImagesViz(t *testing.T) {
|
|
|
|
+ //FIXME: Implement this test (or remove this endpoint)
|
|
|
|
+ t.Log("Test on implemented")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestGetImagesSearch(t *testing.T) {
|
|
runtime, err := newTestRuntime()
|
|
runtime, err := newTestRuntime()
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
@@ -145,21 +154,28 @@ func TestInfo(t *testing.T) {
|
|
|
|
|
|
srv := &Server{runtime: runtime}
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
|
- body, err := getInfo(srv, nil, nil, nil)
|
|
|
|
|
|
+ req, err := http.NewRequest("GET", "/images/search?term=redis", nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- infos := &ApiInfo{}
|
|
|
|
- err = json.Unmarshal(body, infos)
|
|
|
|
|
|
+
|
|
|
|
+ body, err := getImagesSearch(srv, nil, req, nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- if infos.Version != VERSION {
|
|
|
|
- t.Errorf("Excepted version %s, %s found", VERSION, infos.Version)
|
|
|
|
|
|
+
|
|
|
|
+ results := []ApiSearch{}
|
|
|
|
+
|
|
|
|
+ err = json.Unmarshal(body, &results)
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+ if len(results) < 2 {
|
|
|
|
+ t.Errorf("Excepted at least 2 lines, %d found", len(results))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func TestHistory(t *testing.T) {
|
|
|
|
|
|
+func TestGetImagesHistory(t *testing.T) {
|
|
runtime, err := newTestRuntime()
|
|
runtime, err := newTestRuntime()
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
@@ -184,7 +200,7 @@ func TestHistory(t *testing.T) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func TestImagesSearch(t *testing.T) {
|
|
|
|
|
|
+func TestGetImagesByName(t *testing.T) {
|
|
runtime, err := newTestRuntime()
|
|
runtime, err := newTestRuntime()
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
@@ -193,28 +209,92 @@ func TestImagesSearch(t *testing.T) {
|
|
|
|
|
|
srv := &Server{runtime: runtime}
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
|
- req, err := http.NewRequest("GET", "/images/search?term=redis", nil)
|
|
|
|
|
|
+ body, err := getImagesByName(srv, nil, nil, map[string]string{"name": unitTestImageName})
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := getImagesSearch(srv, nil, req, nil)
|
|
|
|
|
|
+ img := &Image{}
|
|
|
|
+
|
|
|
|
+ err = json.Unmarshal(body, img)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
+ if img.Comment != "Imported from http://get.docker.io/images/busybox" {
|
|
|
|
+ t.Errorf("Error inspecting image")
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
- results := []ApiSearch{}
|
|
|
|
|
|
+func TestGetContainersPs(t *testing.T) {
|
|
|
|
+ runtime, err := newTestRuntime()
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+ defer nuke(runtime)
|
|
|
|
|
|
- err = json.Unmarshal(body, &results)
|
|
|
|
|
|
+ srv := &Server{runtime: runtime}
|
|
|
|
+
|
|
|
|
+ container, err := NewBuilder(runtime).Create(&Config{
|
|
|
|
+ Image: GetTestImage(runtime).Id,
|
|
|
|
+ Cmd: []string{"echo", "test"},
|
|
|
|
+ })
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- if len(results) < 2 {
|
|
|
|
- t.Errorf("Excepted at least 2 lines, %d found", len(results))
|
|
|
|
|
|
+ defer runtime.Destroy(container)
|
|
|
|
+
|
|
|
|
+ req, err := http.NewRequest("GET", "/containers?quiet=1&all=1", nil)
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ body, err := getContainersPs(srv, nil, req, nil)
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+ containers := []ApiContainers{}
|
|
|
|
+ err = json.Unmarshal(body, &containers)
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+ if len(containers) != 1 {
|
|
|
|
+ t.Fatalf("Excepted %d container, %d found", 1, len(containers))
|
|
|
|
+ }
|
|
|
|
+ if containers[0].Id != container.ShortId() {
|
|
|
|
+ t.Fatalf("Container ID mismatch. Expected: %s, received: %s\n", container.ShortId(), containers[0].Id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func TestGetImage(t *testing.T) {
|
|
|
|
|
|
+func TestGetContainersExport(t *testing.T) {
|
|
|
|
+ //FIXME: Implement this test
|
|
|
|
+ t.Log("Test on implemented")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestGetContainerChanges(t *testing.T) {
|
|
|
|
+ // FIXME: Implement this test
|
|
|
|
+ t.Log("Test on implemented")
|
|
|
|
+ // r := httptest.NewRecorder()
|
|
|
|
+
|
|
|
|
+ // req, err := http.NewRequest("GET", "/containers/"+id+"/changes", nil)
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // t.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // body, err := getContainersChanges(srv, r, req, nil)
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // t.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // if body == nil {
|
|
|
|
+ // t.Fatalf("Body expected, received: nil\n")
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // if r.Code != http.StatusOK {
|
|
|
|
+ // t.Fatalf("%d OK expected, received %d\n", http.StatusNoContent, r.Code)
|
|
|
|
+ // }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestPostAuth(t *testing.T) {
|
|
runtime, err := newTestRuntime()
|
|
runtime, err := newTestRuntime()
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
@@ -223,22 +303,58 @@ func TestGetImage(t *testing.T) {
|
|
|
|
|
|
srv := &Server{runtime: runtime}
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
|
- body, err := getImagesByName(srv, nil, nil, map[string]string{"name": unitTestImageName})
|
|
|
|
|
|
+ authConfigOrig := &auth.AuthConfig{
|
|
|
|
+ Username: "utest",
|
|
|
|
+ Email: "utest@yopmail.com",
|
|
|
|
+ }
|
|
|
|
+ runtime.authConfig = authConfigOrig
|
|
|
|
+
|
|
|
|
+ body, err := getAuth(srv, nil, nil, nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- img := &Image{}
|
|
|
|
-
|
|
|
|
- err = json.Unmarshal(body, img)
|
|
|
|
|
|
+ authConfig := &auth.AuthConfig{}
|
|
|
|
+ err = json.Unmarshal(body, authConfig)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- if img.Comment != "Imported from http://get.docker.io/images/busybox" {
|
|
|
|
- t.Errorf("Error inspecting image")
|
|
|
|
|
|
+
|
|
|
|
+ if authConfig.Username != authConfigOrig.Username || authConfig.Email != authConfigOrig.Email {
|
|
|
|
+ t.Errorf("The retrieve auth mismatch with the one set.")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func TestPostCommit(t *testing.T) {
|
|
|
|
+ //FIXME: Implement this test
|
|
|
|
+ t.Log("Test on implemented")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestPostBuild(t *testing.T) {
|
|
|
|
+ //FIXME: Implement this test
|
|
|
|
+ t.Log("Test on implemented")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestPostImagesCreate(t *testing.T) {
|
|
|
|
+ //FIXME: Implement this test
|
|
|
|
+ t.Log("Test on implemented")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestPostImagesInsert(t *testing.T) {
|
|
|
|
+ //FIXME: Implement this test (or remove this endpoint)
|
|
|
|
+ t.Log("Test on implemented")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestPostImagesPush(t *testing.T) {
|
|
|
|
+ //FIXME: Implement this test
|
|
|
|
+ t.Log("Test on implemented")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestPostImagesTag(t *testing.T) {
|
|
|
|
+ //FIXME: Implement this test
|
|
|
|
+ t.Log("Test on implemented")
|
|
|
|
+}
|
|
|
|
+
|
|
func TestPostContainersCreate(t *testing.T) {
|
|
func TestPostContainersCreate(t *testing.T) {
|
|
runtime, err := newTestRuntime()
|
|
runtime, err := newTestRuntime()
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -295,7 +411,7 @@ func TestPostContainersCreate(t *testing.T) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func TestGetContainersPs(t *testing.T) {
|
|
|
|
|
|
+func TestPostContainersKill(t *testing.T) {
|
|
runtime, err := newTestRuntime()
|
|
runtime, err := newTestRuntime()
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
@@ -304,38 +420,47 @@ func TestGetContainersPs(t *testing.T) {
|
|
|
|
|
|
srv := &Server{runtime: runtime}
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
|
- container, err := NewBuilder(runtime).Create(&Config{
|
|
|
|
- Image: GetTestImage(runtime).Id,
|
|
|
|
- Cmd: []string{"echo", "test"},
|
|
|
|
- })
|
|
|
|
|
|
+ container, err := NewBuilder(runtime).Create(
|
|
|
|
+ &Config{
|
|
|
|
+ Image: GetTestImage(runtime).Id,
|
|
|
|
+ Cmd: []string{"/bin/cat"},
|
|
|
|
+ OpenStdin: true,
|
|
|
|
+ },
|
|
|
|
+ )
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
defer runtime.Destroy(container)
|
|
defer runtime.Destroy(container)
|
|
|
|
|
|
- req, err := http.NewRequest("GET", "/containers?quiet=1&all=1", nil)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := container.Start(); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := getContainersPs(srv, nil, req, nil)
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
|
|
+ // Give some time to the process to start
|
|
|
|
+ container.WaitTimeout(500 * time.Millisecond)
|
|
|
|
+
|
|
|
|
+ if !container.State.Running {
|
|
|
|
+ t.Errorf("Container should be running")
|
|
}
|
|
}
|
|
- containers := []ApiContainers{}
|
|
|
|
- err = json.Unmarshal(body, &containers)
|
|
|
|
|
|
+
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+
|
|
|
|
+ body, err := postContainersKill(srv, r, nil, map[string]string{"name": container.Id})
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- if len(containers) != 1 {
|
|
|
|
- t.Fatalf("Excepted %d container, %d found", 1, len(containers))
|
|
|
|
|
|
+ if body != nil {
|
|
|
|
+ t.Fatalf("No body expected, received: %s\n", body)
|
|
}
|
|
}
|
|
- if containers[0].Id != container.ShortId() {
|
|
|
|
- t.Fatalf("Container ID mismatch. Expected: %s, received: %s\n", container.ShortId(), containers[0].Id)
|
|
|
|
|
|
+ if r.Code != http.StatusNoContent {
|
|
|
|
+ t.Fatalf("%d NO CONTENT expected, received %d\n", http.StatusNoContent, r.Code)
|
|
|
|
+ }
|
|
|
|
+ if container.State.Running {
|
|
|
|
+ t.Fatalf("The container hasn't been killed")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func TestPostContainersStart(t *testing.T) {
|
|
|
|
|
|
+func TestPostContainersRestart(t *testing.T) {
|
|
runtime, err := newTestRuntime()
|
|
runtime, err := newTestRuntime()
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
@@ -356,9 +481,24 @@ func TestPostContainersStart(t *testing.T) {
|
|
}
|
|
}
|
|
defer runtime.Destroy(container)
|
|
defer runtime.Destroy(container)
|
|
|
|
|
|
|
|
+ if err := container.Start(); err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Give some time to the process to start
|
|
|
|
+ container.WaitTimeout(500 * time.Millisecond)
|
|
|
|
+
|
|
|
|
+ if !container.State.Running {
|
|
|
|
+ t.Errorf("Container should be running")
|
|
|
|
+ }
|
|
|
|
+
|
|
r := httptest.NewRecorder()
|
|
r := httptest.NewRecorder()
|
|
|
|
|
|
- body, err := postContainersStart(srv, r, nil, map[string]string{"name": container.Id})
|
|
|
|
|
|
+ req, err := http.NewRequest("POST", "/containers/"+container.Id+"/restart?t=1", bytes.NewReader([]byte{}))
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+ body, err := postContainersRestart(srv, r, req, map[string]string{"name": container.Id})
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
@@ -369,15 +509,11 @@ func TestPostContainersStart(t *testing.T) {
|
|
t.Fatalf("%d NO CONTENT expected, received %d\n", http.StatusNoContent, r.Code)
|
|
t.Fatalf("%d NO CONTENT expected, received %d\n", http.StatusNoContent, r.Code)
|
|
}
|
|
}
|
|
|
|
|
|
- // Give some time to the process to start
|
|
|
|
|
|
+ // Give some time to the process to restart
|
|
container.WaitTimeout(500 * time.Millisecond)
|
|
container.WaitTimeout(500 * time.Millisecond)
|
|
|
|
|
|
if !container.State.Running {
|
|
if !container.State.Running {
|
|
- t.Errorf("Container should be running")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if _, err = postContainersStart(srv, r, nil, map[string]string{"name": container.Id}); err == nil {
|
|
|
|
- t.Fatalf("A running containter should be able to be started")
|
|
|
|
|
|
+ t.Fatalf("Container should be running")
|
|
}
|
|
}
|
|
|
|
|
|
if err := container.Kill(); err != nil {
|
|
if err := container.Kill(); err != nil {
|
|
@@ -385,34 +521,56 @@ func TestPostContainersStart(t *testing.T) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func testContainerRestart(t *testing.T, srv *Server, id string) {
|
|
|
|
|
|
+func TestPostContainersStart(t *testing.T) {
|
|
|
|
+ runtime, err := newTestRuntime()
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+ defer nuke(runtime)
|
|
|
|
|
|
- r := httptest.NewRecorder()
|
|
|
|
|
|
+ srv := &Server{runtime: runtime}
|
|
|
|
|
|
- req, err := http.NewRequest("POST", "/containers/"+id+"/restart?t=1", nil)
|
|
|
|
|
|
+ container, err := NewBuilder(runtime).Create(
|
|
|
|
+ &Config{
|
|
|
|
+ Image: GetTestImage(runtime).Id,
|
|
|
|
+ Cmd: []string{"/bin/cat"},
|
|
|
|
+ OpenStdin: true,
|
|
|
|
+ },
|
|
|
|
+ )
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
+ defer runtime.Destroy(container)
|
|
|
|
|
|
- body, err := postContainersRestart(srv, r, req, nil)
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+
|
|
|
|
+ body, err := postContainersStart(srv, r, nil, map[string]string{"name": container.Id})
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
-
|
|
|
|
if body != nil {
|
|
if body != nil {
|
|
t.Fatalf("No body expected, received: %s\n", body)
|
|
t.Fatalf("No body expected, received: %s\n", body)
|
|
}
|
|
}
|
|
-
|
|
|
|
if r.Code != http.StatusNoContent {
|
|
if r.Code != http.StatusNoContent {
|
|
t.Fatalf("%d NO CONTENT expected, received %d\n", http.StatusNoContent, r.Code)
|
|
t.Fatalf("%d NO CONTENT expected, received %d\n", http.StatusNoContent, r.Code)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Give some time to the process to start
|
|
|
|
+ container.WaitTimeout(500 * time.Millisecond)
|
|
|
|
+
|
|
|
|
+ if !container.State.Running {
|
|
|
|
+ t.Errorf("Container should be running")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if _, err = postContainersStart(srv, r, nil, map[string]string{"name": container.Id}); err == nil {
|
|
|
|
+ t.Fatalf("A running containter should be able to be started")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if err := container.Kill(); err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
-// testContainerRestart(t, srv, id)
|
|
|
|
-// testContainerKill(t, srv, id)
|
|
|
|
-// testContainerWait(t, srv, id)
|
|
|
|
-// testDeleteContainer(t, srv, id)
|
|
|
|
-// testListContainers(t, srv, 0)
|
|
|
|
func TestPostContainersStop(t *testing.T) {
|
|
func TestPostContainersStop(t *testing.T) {
|
|
runtime, err := newTestRuntime()
|
|
runtime, err := newTestRuntime()
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -467,54 +625,55 @@ func TestPostContainersStop(t *testing.T) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func testContainerKill(t *testing.T, srv *Server, id string) {
|
|
|
|
-
|
|
|
|
- r := httptest.NewRecorder()
|
|
|
|
-
|
|
|
|
- req, err := http.NewRequest("POST", "/containers/"+id+"/kill", nil)
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- body, err := postContainersKill(srv, r, req, nil)
|
|
|
|
|
|
+func TestPostContainersWait(t *testing.T) {
|
|
|
|
+ runtime, err := newTestRuntime()
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
+ defer nuke(runtime)
|
|
|
|
|
|
- if body != nil {
|
|
|
|
- t.Fatalf("No body expected, received: %s\n", body)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if r.Code != http.StatusNoContent {
|
|
|
|
- t.Fatalf("%d NO CONTENT expected, received %d\n", http.StatusNoContent, r.Code)
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func testContainerWait(t *testing.T, srv *Server, id string) {
|
|
|
|
-
|
|
|
|
- r := httptest.NewRecorder()
|
|
|
|
-
|
|
|
|
- req, err := http.NewRequest("POST", "/containers/"+id+"/wait", nil)
|
|
|
|
- req.Header.Set("Content-Type", "plain/text")
|
|
|
|
|
|
+ srv := &Server{runtime: runtime}
|
|
|
|
|
|
|
|
+ container, err := NewBuilder(runtime).Create(
|
|
|
|
+ &Config{
|
|
|
|
+ Image: GetTestImage(runtime).Id,
|
|
|
|
+ Cmd: []string{"/bin/sleep", "1"},
|
|
|
|
+ OpenStdin: true,
|
|
|
|
+ },
|
|
|
|
+ )
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
+ defer runtime.Destroy(container)
|
|
|
|
|
|
- body, err := postContainersWait(srv, r, req, nil)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := container.Start(); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- if body == nil {
|
|
|
|
- t.Fatalf("Body expected, received: nil\n")
|
|
|
|
- }
|
|
|
|
|
|
+ setTimeout(t, "Wait timed out", 3*time.Second, func() {
|
|
|
|
+ body, err := postContainersWait(srv, nil, nil, nil)
|
|
|
|
+ if err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+ apiWait := &ApiWait{}
|
|
|
|
+ if err := json.Unmarshal(body, apiWait); err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+ if apiWait.StatusCode != 0 {
|
|
|
|
+ t.Fatalf("Non zero exit code for sleep: %d\n", apiWait.StatusCode)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
|
|
- if r.Code != http.StatusOK {
|
|
|
|
- t.Fatalf("%d OK expected, received %d\n", http.StatusNoContent, r.Code)
|
|
|
|
|
|
+ if container.State.Running {
|
|
|
|
+ t.Fatalf("The container should be stopped after wait")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func TestPostContainersAttach(t *testing.T) {
|
|
|
|
+ //FIXME: Implement this test
|
|
|
|
+ t.Log("Test on implemented")
|
|
|
|
+}
|
|
|
|
+
|
|
// FIXME: Test deleting runnign container
|
|
// FIXME: Test deleting runnign container
|
|
// FIXME: Test deleting container with volume
|
|
// FIXME: Test deleting container with volume
|
|
// FIXME: Test deleting volume in use by other container
|
|
// FIXME: Test deleting volume in use by other container
|
|
@@ -567,25 +726,7 @@ func TestDeleteContainers(t *testing.T) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func testContainerChanges(t *testing.T, srv *Server, id string) {
|
|
|
|
-
|
|
|
|
- r := httptest.NewRecorder()
|
|
|
|
-
|
|
|
|
- req, err := http.NewRequest("GET", "/containers/"+id+"/changes", nil)
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- body, err := getContainersChanges(srv, r, req, nil)
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if body == nil {
|
|
|
|
- t.Fatalf("Body expected, received: nil\n")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if r.Code != http.StatusOK {
|
|
|
|
- t.Fatalf("%d OK expected, received %d\n", http.StatusNoContent, r.Code)
|
|
|
|
- }
|
|
|
|
|
|
+func TestDeleteImages(t *testing.T) {
|
|
|
|
+ //FIXME: Implement this test
|
|
|
|
+ t.Log("Test on implemented")
|
|
}
|
|
}
|