|
@@ -1,6 +1,7 @@
|
|
package docker
|
|
package docker
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "archive/tar"
|
|
"bufio"
|
|
"bufio"
|
|
"bytes"
|
|
"bytes"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
@@ -11,7 +12,6 @@ import (
|
|
"net/http/httptest"
|
|
"net/http/httptest"
|
|
"os"
|
|
"os"
|
|
"path"
|
|
"path"
|
|
- "strings"
|
|
|
|
"testing"
|
|
"testing"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
@@ -43,13 +43,9 @@ func TestGetAuth(t *testing.T) {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := postAuth(srv, r, req, nil)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := postAuth(srv, r, req, nil); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- if body == nil {
|
|
|
|
- t.Fatalf("No body received\n")
|
|
|
|
- }
|
|
|
|
if r.Code != http.StatusOK && r.Code != 0 {
|
|
if r.Code != http.StatusOK && r.Code != 0 {
|
|
t.Fatalf("%d OK or 0 expected, received %d\n", http.StatusOK, r.Code)
|
|
t.Fatalf("%d OK or 0 expected, received %d\n", http.StatusOK, r.Code)
|
|
}
|
|
}
|
|
@@ -70,15 +66,14 @@ func TestGetVersion(t *testing.T) {
|
|
|
|
|
|
srv := &Server{runtime: runtime}
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
|
- body, err := getVersion(srv, nil, nil, nil)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+
|
|
|
|
+ if err := getVersion(srv, r, nil, nil); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
v := &ApiVersion{}
|
|
v := &ApiVersion{}
|
|
-
|
|
|
|
- err = json.Unmarshal(body, v)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err = json.Unmarshal(r.Body.Bytes(), v); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if v.Version != VERSION {
|
|
if v.Version != VERSION {
|
|
@@ -95,12 +90,14 @@ func TestGetInfo(t *testing.T) {
|
|
|
|
|
|
srv := &Server{runtime: runtime}
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
|
- body, err := getInfo(srv, nil, nil, nil)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+
|
|
|
|
+ if err := getInfo(srv, r, nil, nil); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
+
|
|
infos := &ApiInfo{}
|
|
infos := &ApiInfo{}
|
|
- err = json.Unmarshal(body, infos)
|
|
|
|
|
|
+ err = json.Unmarshal(r.Body.Bytes(), infos)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
@@ -124,14 +121,14 @@ func TestGetImagesJson(t *testing.T) {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := getImagesJson(srv, nil, req, nil)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+
|
|
|
|
+ if err := getImagesJson(srv, r, req, nil); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
images := []ApiImages{}
|
|
images := []ApiImages{}
|
|
- err = json.Unmarshal(body, &images)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := json.Unmarshal(r.Body.Bytes(), &images); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -139,24 +136,24 @@ func TestGetImagesJson(t *testing.T) {
|
|
t.Errorf("Excepted 1 image, %d found", len(images))
|
|
t.Errorf("Excepted 1 image, %d found", len(images))
|
|
}
|
|
}
|
|
|
|
|
|
- if images[0].Repository != "docker-ut" {
|
|
|
|
- t.Errorf("Excepted image docker-ut, %s found", images[0].Repository)
|
|
|
|
|
|
+ if images[0].Repository != unitTestImageName {
|
|
|
|
+ t.Errorf("Excepted image %s, %s found", unitTestImageName, images[0].Repository)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ r2 := httptest.NewRecorder()
|
|
|
|
+
|
|
// only_ids=1&all=1
|
|
// only_ids=1&all=1
|
|
req2, err := http.NewRequest("GET", "/images/json?only_ids=1&all=1", nil)
|
|
req2, err := http.NewRequest("GET", "/images/json?only_ids=1&all=1", nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- body2, err := getImagesJson(srv, nil, req2, nil)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := getImagesJson(srv, r2, req2, nil); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
images2 := []ApiImages{}
|
|
images2 := []ApiImages{}
|
|
- err = json.Unmarshal(body2, &images2)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := json.Unmarshal(r2.Body.Bytes(), &images2); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -168,24 +165,24 @@ func TestGetImagesJson(t *testing.T) {
|
|
t.Errorf("Excepted no image Repository, %s found", images2[0].Repository)
|
|
t.Errorf("Excepted no image Repository, %s found", images2[0].Repository)
|
|
}
|
|
}
|
|
|
|
|
|
- if images2[0].Id == "" {
|
|
|
|
- t.Errorf("Excepted image Id, %s found", images2[0].Id)
|
|
|
|
|
|
+ if images2[0].Id != GetTestImage(runtime).ShortId() {
|
|
|
|
+ t.Errorf("Retrieved image Id differs, expected %s, received %s", GetTestImage(runtime).ShortId(), images2[0].Id)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ r3 := httptest.NewRecorder()
|
|
|
|
+
|
|
// filter=a
|
|
// filter=a
|
|
req3, err := http.NewRequest("GET", "/images/json?filter=a", nil)
|
|
req3, err := http.NewRequest("GET", "/images/json?filter=a", nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- body3, err := getImagesJson(srv, nil, req3, nil)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := getImagesJson(srv, r3, req3, nil); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
images3 := []ApiImages{}
|
|
images3 := []ApiImages{}
|
|
- err = json.Unmarshal(body3, &images3)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := json.Unmarshal(r3.Body.Bytes(), &images3); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -204,9 +201,7 @@ func TestGetImagesViz(t *testing.T) {
|
|
srv := &Server{runtime: runtime}
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
|
r := httptest.NewRecorder()
|
|
r := httptest.NewRecorder()
|
|
-
|
|
|
|
- _, err = getImagesViz(srv, r, nil, nil)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := getImagesViz(srv, r, nil, nil); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -233,20 +228,19 @@ func TestGetImagesSearch(t *testing.T) {
|
|
|
|
|
|
srv := &Server{runtime: runtime}
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+
|
|
req, err := http.NewRequest("GET", "/images/search?term=redis", nil)
|
|
req, err := http.NewRequest("GET", "/images/search?term=redis", nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := getImagesSearch(srv, nil, req, nil)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := getImagesSearch(srv, r, req, nil); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
results := []ApiSearch{}
|
|
results := []ApiSearch{}
|
|
-
|
|
|
|
- err = json.Unmarshal(body, &results)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := json.Unmarshal(r.Body.Bytes(), &results); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if len(results) < 2 {
|
|
if len(results) < 2 {
|
|
@@ -263,15 +257,14 @@ func TestGetImagesHistory(t *testing.T) {
|
|
|
|
|
|
srv := &Server{runtime: runtime}
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
|
- body, err := getImagesHistory(srv, nil, nil, map[string]string{"name": unitTestImageName})
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+
|
|
|
|
+ if err := getImagesHistory(srv, r, nil, map[string]string{"name": unitTestImageName}); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
history := []ApiHistory{}
|
|
history := []ApiHistory{}
|
|
-
|
|
|
|
- err = json.Unmarshal(body, &history)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := json.Unmarshal(r.Body.Bytes(), &history); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if len(history) != 1 {
|
|
if len(history) != 1 {
|
|
@@ -288,18 +281,16 @@ func TestGetImagesByName(t *testing.T) {
|
|
|
|
|
|
srv := &Server{runtime: runtime}
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
|
- body, err := getImagesByName(srv, nil, nil, map[string]string{"name": unitTestImageName})
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+ if err := getImagesByName(srv, r, nil, map[string]string{"name": unitTestImageName}); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
img := &Image{}
|
|
img := &Image{}
|
|
-
|
|
|
|
- err = json.Unmarshal(body, img)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := json.Unmarshal(r.Body.Bytes(), img); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- if img.Comment != "Imported from http://get.docker.io/images/busybox" {
|
|
|
|
|
|
+ if img.Id != GetTestImage(runtime).Id || img.Comment != "Imported from http://get.docker.io/images/busybox" {
|
|
t.Errorf("Error inspecting image")
|
|
t.Errorf("Error inspecting image")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -327,13 +318,12 @@ func TestGetContainersPs(t *testing.T) {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := getContainersPs(srv, nil, req, nil)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+ if err := getContainersPs(srv, r, req, nil); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
containers := []ApiContainers{}
|
|
containers := []ApiContainers{}
|
|
- err = json.Unmarshal(body, &containers)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := json.Unmarshal(r.Body.Bytes(), &containers); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if len(containers) != 1 {
|
|
if len(containers) != 1 {
|
|
@@ -359,7 +349,7 @@ func TestGetContainersExport(t *testing.T) {
|
|
container, err := builder.Create(
|
|
container, err := builder.Create(
|
|
&Config{
|
|
&Config{
|
|
Image: GetTestImage(runtime).Id,
|
|
Image: GetTestImage(runtime).Id,
|
|
- Cmd: []string{"/bin/rm", "/etc/passwd"},
|
|
|
|
|
|
+ Cmd: []string{"touch", "/test"},
|
|
},
|
|
},
|
|
)
|
|
)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -372,9 +362,7 @@ func TestGetContainersExport(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
r := httptest.NewRecorder()
|
|
r := httptest.NewRecorder()
|
|
-
|
|
|
|
- _, err = getContainersExport(srv, r, nil, map[string]string{"name": container.Id})
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err = getContainersExport(srv, r, nil, map[string]string{"name": container.Id}); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -382,8 +370,22 @@ func TestGetContainersExport(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)
|
|
}
|
|
}
|
|
|
|
|
|
- if r.Body == nil {
|
|
|
|
- t.Fatalf("Body expected, found 0")
|
|
|
|
|
|
+ found := false
|
|
|
|
+ for tarReader := tar.NewReader(r.Body); ; {
|
|
|
|
+ h, err := tarReader.Next()
|
|
|
|
+ if err != nil {
|
|
|
|
+ if err == io.EOF {
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+ if h.Name == "./test" {
|
|
|
|
+ found = true
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if !found {
|
|
|
|
+ t.Fatalf("The created test file has not been found in the exported image")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -414,12 +416,12 @@ func TestGetContainersChanges(t *testing.T) {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := getContainersChanges(srv, nil, nil, map[string]string{"name": container.Id})
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+ if err := getContainersChanges(srv, r, nil, map[string]string{"name": container.Id}); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
changes := []Change{}
|
|
changes := []Change{}
|
|
- if err := json.Unmarshal(body, &changes); err != nil {
|
|
|
|
|
|
+ if err := json.Unmarshal(r.Body.Bytes(), &changes); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -450,7 +452,7 @@ func TestGetContainersByName(t *testing.T) {
|
|
container, err := builder.Create(
|
|
container, err := builder.Create(
|
|
&Config{
|
|
&Config{
|
|
Image: GetTestImage(runtime).Id,
|
|
Image: GetTestImage(runtime).Id,
|
|
- Cmd: []string{"/bin/rm", "/etc/passwd"},
|
|
|
|
|
|
+ Cmd: []string{"echo", "test"},
|
|
},
|
|
},
|
|
)
|
|
)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -458,14 +460,17 @@ func TestGetContainersByName(t *testing.T) {
|
|
}
|
|
}
|
|
defer runtime.Destroy(container)
|
|
defer runtime.Destroy(container)
|
|
|
|
|
|
- body, err := getContainersByName(srv, nil, nil, map[string]string{"name": container.Id})
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+ if err := getContainersByName(srv, r, nil, map[string]string{"name": container.Id}); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- outContainer := Container{}
|
|
|
|
- if err := json.Unmarshal(body, &outContainer); err != nil {
|
|
|
|
|
|
+ outContainer := &Container{}
|
|
|
|
+ if err := json.Unmarshal(r.Body.Bytes(), outContainer); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
+ if outContainer.Id != container.Id {
|
|
|
|
+ t.Fatalf("Wrong containers retrieved. Expected %s, recieved %s", container.Id, outContainer.Id)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
func TestPostAuth(t *testing.T) {
|
|
func TestPostAuth(t *testing.T) {
|
|
@@ -483,14 +488,13 @@ func TestPostAuth(t *testing.T) {
|
|
}
|
|
}
|
|
runtime.authConfig = authConfigOrig
|
|
runtime.authConfig = authConfigOrig
|
|
|
|
|
|
- body, err := getAuth(srv, nil, nil, nil)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+ if err := getAuth(srv, r, nil, nil); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
authConfig := &auth.AuthConfig{}
|
|
authConfig := &auth.AuthConfig{}
|
|
- err = json.Unmarshal(body, authConfig)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := json.Unmarshal(r.Body.Bytes(), authConfig); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -508,15 +512,13 @@ func TestPostCommit(t *testing.T) {
|
|
|
|
|
|
srv := &Server{runtime: runtime}
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
|
- r := httptest.NewRecorder()
|
|
|
|
-
|
|
|
|
builder := NewBuilder(runtime)
|
|
builder := NewBuilder(runtime)
|
|
|
|
|
|
// Create a container and remove a file
|
|
// Create a container and remove a file
|
|
container, err := builder.Create(
|
|
container, err := builder.Create(
|
|
&Config{
|
|
&Config{
|
|
Image: GetTestImage(runtime).Id,
|
|
Image: GetTestImage(runtime).Id,
|
|
- Cmd: []string{"/bin/rm", "/etc/passwd"},
|
|
|
|
|
|
+ Cmd: []string{"touch", "/test"},
|
|
},
|
|
},
|
|
)
|
|
)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -533,17 +535,21 @@ func TestPostCommit(t *testing.T) {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := postCommit(srv, r, req, nil)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+ if err := postCommit(srv, r, req, nil); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
-
|
|
|
|
- if body == nil {
|
|
|
|
- t.Fatalf("Body expected, received: 0\n")
|
|
|
|
- }
|
|
|
|
if r.Code != http.StatusCreated {
|
|
if r.Code != http.StatusCreated {
|
|
t.Fatalf("%d Created expected, received %d\n", http.StatusCreated, r.Code)
|
|
t.Fatalf("%d Created expected, received %d\n", http.StatusCreated, r.Code)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ apiId := &ApiId{}
|
|
|
|
+ if err := json.Unmarshal(r.Body.Bytes(), apiId); err != nil {
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+ if _, err := runtime.graph.Get(apiId.Id); err != nil {
|
|
|
|
+ t.Fatalf("The image has not been commited")
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
func TestPostBuild(t *testing.T) {
|
|
func TestPostBuild(t *testing.T) {
|
|
@@ -560,20 +566,16 @@ func TestPostBuild(t *testing.T) {
|
|
|
|
|
|
c1 := make(chan struct{})
|
|
c1 := make(chan struct{})
|
|
go func() {
|
|
go func() {
|
|
|
|
+ defer close(c1)
|
|
r := &hijackTester{
|
|
r := &hijackTester{
|
|
ResponseRecorder: httptest.NewRecorder(),
|
|
ResponseRecorder: httptest.NewRecorder(),
|
|
in: stdin,
|
|
in: stdin,
|
|
out: stdoutPipe,
|
|
out: stdoutPipe,
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := postBuild(srv, r, nil, nil)
|
|
|
|
- close(c1)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := postBuild(srv, r, nil, nil); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- if body != nil {
|
|
|
|
- t.Fatalf("No body expected, received: %s\n", body)
|
|
|
|
- }
|
|
|
|
}()
|
|
}()
|
|
|
|
|
|
// Acknowledge hijack
|
|
// Acknowledge hijack
|
|
@@ -601,163 +603,169 @@ func TestPostBuild(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
func TestPostImagesCreate(t *testing.T) {
|
|
func TestPostImagesCreate(t *testing.T) {
|
|
- runtime, err := newTestRuntime()
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
- defer nuke(runtime)
|
|
|
|
-
|
|
|
|
- srv := &Server{runtime: runtime}
|
|
|
|
-
|
|
|
|
- stdin, stdinPipe := io.Pipe()
|
|
|
|
- stdout, stdoutPipe := io.Pipe()
|
|
|
|
-
|
|
|
|
- c1 := make(chan struct{})
|
|
|
|
- go func() {
|
|
|
|
- r := &hijackTester{
|
|
|
|
- ResponseRecorder: httptest.NewRecorder(),
|
|
|
|
- in: stdin,
|
|
|
|
- out: stdoutPipe,
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- req, err := http.NewRequest("POST", "/images/create?fromImage=docker-ut", bytes.NewReader([]byte{}))
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- body, err := postImagesCreate(srv, r, req, nil)
|
|
|
|
- close(c1)
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
- if body != nil {
|
|
|
|
- t.Fatalf("No body expected, received: %s\n", body)
|
|
|
|
- }
|
|
|
|
- }()
|
|
|
|
-
|
|
|
|
- // Acknowledge hijack
|
|
|
|
- setTimeout(t, "hijack acknowledge timed out", 2*time.Second, func() {
|
|
|
|
- stdout.Read([]byte{})
|
|
|
|
- stdout.Read(make([]byte, 4096))
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- setTimeout(t, "Waiting for imagesCreate output", 5*time.Second, func() {
|
|
|
|
- reader := bufio.NewReader(stdout)
|
|
|
|
- line, err := reader.ReadString('\n')
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
- if !strings.HasPrefix(line, "Pulling repository docker-ut from") {
|
|
|
|
- t.Fatalf("Expected Pulling repository docker-ut from..., found %s", line)
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- // Close pipes (client disconnects)
|
|
|
|
- if err := closeWrap(stdin, stdinPipe, stdout, stdoutPipe); err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Wait for imagesCreate to finish, the client disconnected, therefore, Create finished his job
|
|
|
|
- setTimeout(t, "Waiting for imagesCreate timed out", 10*time.Second, func() {
|
|
|
|
- <-c1
|
|
|
|
- })
|
|
|
|
|
|
+ // FIXME: Use the staging in order to perform tests
|
|
|
|
+
|
|
|
|
+ // runtime, err := newTestRuntime()
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // t.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+ // defer nuke(runtime)
|
|
|
|
+
|
|
|
|
+ // srv := &Server{runtime: runtime}
|
|
|
|
+
|
|
|
|
+ // stdin, stdinPipe := io.Pipe()
|
|
|
|
+ // stdout, stdoutPipe := io.Pipe()
|
|
|
|
+
|
|
|
|
+ // c1 := make(chan struct{})
|
|
|
|
+ // go func() {
|
|
|
|
+ // defer close(c1)
|
|
|
|
+
|
|
|
|
+ // r := &hijackTester{
|
|
|
|
+ // ResponseRecorder: httptest.NewRecorder(),
|
|
|
|
+ // in: stdin,
|
|
|
|
+ // out: stdoutPipe,
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // req, err := http.NewRequest("POST", "/images/create?fromImage="+unitTestImageName, bytes.NewReader([]byte{}))
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // t.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // body, err := postImagesCreate(srv, r, req, nil)
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // t.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+ // if body != nil {
|
|
|
|
+ // t.Fatalf("No body expected, received: %s\n", body)
|
|
|
|
+ // }
|
|
|
|
+ // }()
|
|
|
|
+
|
|
|
|
+ // // Acknowledge hijack
|
|
|
|
+ // setTimeout(t, "hijack acknowledge timed out", 2*time.Second, func() {
|
|
|
|
+ // stdout.Read([]byte{})
|
|
|
|
+ // stdout.Read(make([]byte, 4096))
|
|
|
|
+ // })
|
|
|
|
+
|
|
|
|
+ // setTimeout(t, "Waiting for imagesCreate output", 5*time.Second, func() {
|
|
|
|
+ // reader := bufio.NewReader(stdout)
|
|
|
|
+ // line, err := reader.ReadString('\n')
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // t.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+ // if !strings.HasPrefix(line, "Pulling repository d from") {
|
|
|
|
+ // t.Fatalf("Expected Pulling repository docker-ut from..., found %s", line)
|
|
|
|
+ // }
|
|
|
|
+ // })
|
|
|
|
+
|
|
|
|
+ // // Close pipes (client disconnects)
|
|
|
|
+ // if err := closeWrap(stdin, stdinPipe, stdout, stdoutPipe); err != nil {
|
|
|
|
+ // t.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // // Wait for imagesCreate to finish, the client disconnected, therefore, Create finished his job
|
|
|
|
+ // setTimeout(t, "Waiting for imagesCreate timed out", 10*time.Second, func() {
|
|
|
|
+ // <-c1
|
|
|
|
+ // })
|
|
}
|
|
}
|
|
|
|
|
|
-func TestPostImagesInsert(t *testing.T) {
|
|
|
|
- //FIXME: Implement this test (or remove this endpoint)
|
|
|
|
- t.Log("Test not implemented")
|
|
|
|
-}
|
|
|
|
|
|
+// func TestPostImagesInsert(t *testing.T) {
|
|
|
|
+// //FIXME: Implement this test (or remove this endpoint)
|
|
|
|
+// t.Log("Test not implemented")
|
|
|
|
+// }
|
|
|
|
|
|
func TestPostImagesPush(t *testing.T) {
|
|
func TestPostImagesPush(t *testing.T) {
|
|
- runtime, err := newTestRuntime()
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
- defer nuke(runtime)
|
|
|
|
-
|
|
|
|
- srv := &Server{runtime: runtime}
|
|
|
|
-
|
|
|
|
- stdin, stdinPipe := io.Pipe()
|
|
|
|
- stdout, stdoutPipe := io.Pipe()
|
|
|
|
-
|
|
|
|
- c1 := make(chan struct{})
|
|
|
|
- go func() {
|
|
|
|
- r := &hijackTester{
|
|
|
|
- ResponseRecorder: httptest.NewRecorder(),
|
|
|
|
- in: stdin,
|
|
|
|
- out: stdoutPipe,
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- req, err := http.NewRequest("POST", "/images/docker-ut/push", bytes.NewReader([]byte{}))
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- body, err := postImagesPush(srv, r, req, map[string]string{"name": "docker-ut"})
|
|
|
|
- close(c1)
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
- if body != nil {
|
|
|
|
- t.Fatalf("No body expected, received: %s\n", body)
|
|
|
|
- }
|
|
|
|
- }()
|
|
|
|
-
|
|
|
|
- // Acknowledge hijack
|
|
|
|
- setTimeout(t, "hijack acknowledge timed out", 2*time.Second, func() {
|
|
|
|
- stdout.Read([]byte{})
|
|
|
|
- stdout.Read(make([]byte, 4096))
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- setTimeout(t, "Waiting for imagesCreate output", 5*time.Second, func() {
|
|
|
|
- reader := bufio.NewReader(stdout)
|
|
|
|
- line, err := reader.ReadString('\n')
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
- if !strings.HasPrefix(line, "Processing checksum") {
|
|
|
|
- t.Fatalf("Processing checksum..., found %s", line)
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- // Close pipes (client disconnects)
|
|
|
|
- if err := closeWrap(stdin, stdinPipe, stdout, stdoutPipe); err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Wait for imagesPush to finish, the client disconnected, therefore, Push finished his job
|
|
|
|
- setTimeout(t, "Waiting for imagesPush timed out", 10*time.Second, func() {
|
|
|
|
- <-c1
|
|
|
|
- })
|
|
|
|
|
|
+ //FIXME: Use staging in order to perform tests
|
|
|
|
+ // runtime, err := newTestRuntime()
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // t.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+ // defer nuke(runtime)
|
|
|
|
+
|
|
|
|
+ // srv := &Server{runtime: runtime}
|
|
|
|
+
|
|
|
|
+ // stdin, stdinPipe := io.Pipe()
|
|
|
|
+ // stdout, stdoutPipe := io.Pipe()
|
|
|
|
+
|
|
|
|
+ // c1 := make(chan struct{})
|
|
|
|
+ // go func() {
|
|
|
|
+ // r := &hijackTester{
|
|
|
|
+ // ResponseRecorder: httptest.NewRecorder(),
|
|
|
|
+ // in: stdin,
|
|
|
|
+ // out: stdoutPipe,
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // req, err := http.NewRequest("POST", "/images/docker-ut/push", bytes.NewReader([]byte{}))
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // t.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // body, err := postImagesPush(srv, r, req, map[string]string{"name": "docker-ut"})
|
|
|
|
+ // close(c1)
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // t.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+ // if body != nil {
|
|
|
|
+ // t.Fatalf("No body expected, received: %s\n", body)
|
|
|
|
+ // }
|
|
|
|
+ // }()
|
|
|
|
+
|
|
|
|
+ // // Acknowledge hijack
|
|
|
|
+ // setTimeout(t, "hijack acknowledge timed out", 2*time.Second, func() {
|
|
|
|
+ // stdout.Read([]byte{})
|
|
|
|
+ // stdout.Read(make([]byte, 4096))
|
|
|
|
+ // })
|
|
|
|
+
|
|
|
|
+ // setTimeout(t, "Waiting for imagesCreate output", 5*time.Second, func() {
|
|
|
|
+ // reader := bufio.NewReader(stdout)
|
|
|
|
+ // line, err := reader.ReadString('\n')
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // t.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+ // if !strings.HasPrefix(line, "Processing checksum") {
|
|
|
|
+ // t.Fatalf("Processing checksum..., found %s", line)
|
|
|
|
+ // }
|
|
|
|
+ // })
|
|
|
|
+
|
|
|
|
+ // // Close pipes (client disconnects)
|
|
|
|
+ // if err := closeWrap(stdin, stdinPipe, stdout, stdoutPipe); err != nil {
|
|
|
|
+ // t.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // // Wait for imagesPush to finish, the client disconnected, therefore, Push finished his job
|
|
|
|
+ // setTimeout(t, "Waiting for imagesPush timed out", 10*time.Second, func() {
|
|
|
|
+ // <-c1
|
|
|
|
+ // })
|
|
}
|
|
}
|
|
|
|
|
|
func TestPostImagesTag(t *testing.T) {
|
|
func TestPostImagesTag(t *testing.T) {
|
|
- runtime, err := newTestRuntime()
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
- defer nuke(runtime)
|
|
|
|
-
|
|
|
|
- srv := &Server{runtime: runtime}
|
|
|
|
-
|
|
|
|
- r := httptest.NewRecorder()
|
|
|
|
-
|
|
|
|
- req, err := http.NewRequest("POST", "/images/docker-ut/tag?repo=testrepo&tag=testtag", bytes.NewReader([]byte{}))
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- body, err := postImagesTag(srv, r, req, map[string]string{"name": "docker-ut"})
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if body != nil {
|
|
|
|
- t.Fatalf("No body expected, received: %s\n", body)
|
|
|
|
- }
|
|
|
|
- if r.Code != http.StatusCreated {
|
|
|
|
- t.Fatalf("%d Created expected, received %d\n", http.StatusCreated, r.Code)
|
|
|
|
- }
|
|
|
|
|
|
+ // FIXME: Use staging in order to perform tests
|
|
|
|
+
|
|
|
|
+ // runtime, err := newTestRuntime()
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // t.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+ // defer nuke(runtime)
|
|
|
|
+
|
|
|
|
+ // srv := &Server{runtime: runtime}
|
|
|
|
+
|
|
|
|
+ // r := httptest.NewRecorder()
|
|
|
|
+
|
|
|
|
+ // req, err := http.NewRequest("POST", "/images/docker-ut/tag?repo=testrepo&tag=testtag", bytes.NewReader([]byte{}))
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // t.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // body, err := postImagesTag(srv, r, req, map[string]string{"name": "docker-ut"})
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // t.Fatal(err)
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // if body != nil {
|
|
|
|
+ // t.Fatalf("No body expected, received: %s\n", body)
|
|
|
|
+ // }
|
|
|
|
+ // if r.Code != http.StatusCreated {
|
|
|
|
+ // t.Fatalf("%d Created expected, received %d\n", http.StatusCreated, r.Code)
|
|
|
|
+ // }
|
|
}
|
|
}
|
|
|
|
|
|
func TestPostContainersCreate(t *testing.T) {
|
|
func TestPostContainersCreate(t *testing.T) {
|
|
@@ -769,8 +777,6 @@ func TestPostContainersCreate(t *testing.T) {
|
|
|
|
|
|
srv := &Server{runtime: runtime}
|
|
srv := &Server{runtime: runtime}
|
|
|
|
|
|
- r := httptest.NewRecorder()
|
|
|
|
-
|
|
|
|
configJson, err := json.Marshal(&Config{
|
|
configJson, err := json.Marshal(&Config{
|
|
Image: GetTestImage(runtime).Id,
|
|
Image: GetTestImage(runtime).Id,
|
|
Memory: 33554432,
|
|
Memory: 33554432,
|
|
@@ -785,8 +791,8 @@ func TestPostContainersCreate(t *testing.T) {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := postContainersCreate(srv, r, req, nil)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+ if err := postContainersCreate(srv, r, req, nil); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if r.Code != http.StatusCreated {
|
|
if r.Code != http.StatusCreated {
|
|
@@ -794,7 +800,7 @@ func TestPostContainersCreate(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
apiRun := &ApiRun{}
|
|
apiRun := &ApiRun{}
|
|
- if err := json.Unmarshal(body, apiRun); err != nil {
|
|
|
|
|
|
+ if err := json.Unmarshal(r.Body.Bytes(), apiRun); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -849,14 +855,9 @@ func TestPostContainersKill(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
r := httptest.NewRecorder()
|
|
r := httptest.NewRecorder()
|
|
-
|
|
|
|
- body, err := postContainersKill(srv, r, nil, map[string]string{"name": container.Id})
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := postContainersKill(srv, r, nil, map[string]string{"name": container.Id}); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- if body != nil {
|
|
|
|
- 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)
|
|
}
|
|
}
|
|
@@ -897,19 +898,14 @@ func TestPostContainersRestart(t *testing.T) {
|
|
t.Errorf("Container should be running")
|
|
t.Errorf("Container should be running")
|
|
}
|
|
}
|
|
|
|
|
|
- r := httptest.NewRecorder()
|
|
|
|
-
|
|
|
|
req, err := http.NewRequest("POST", "/containers/"+container.Id+"/restart?t=1", bytes.NewReader([]byte{}))
|
|
req, err := http.NewRequest("POST", "/containers/"+container.Id+"/restart?t=1", bytes.NewReader([]byte{}))
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- body, err := postContainersRestart(srv, r, req, map[string]string{"name": container.Id})
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+ if err := postContainersRestart(srv, r, req, map[string]string{"name": container.Id}); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- if body != nil {
|
|
|
|
- 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)
|
|
}
|
|
}
|
|
@@ -948,14 +944,9 @@ func TestPostContainersStart(t *testing.T) {
|
|
defer runtime.Destroy(container)
|
|
defer runtime.Destroy(container)
|
|
|
|
|
|
r := httptest.NewRecorder()
|
|
r := httptest.NewRecorder()
|
|
-
|
|
|
|
- body, err := postContainersStart(srv, r, nil, map[string]string{"name": container.Id})
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := postContainersStart(srv, r, nil, map[string]string{"name": container.Id}); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- if body != nil {
|
|
|
|
- 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)
|
|
}
|
|
}
|
|
@@ -967,7 +958,8 @@ func TestPostContainersStart(t *testing.T) {
|
|
t.Errorf("Container should be running")
|
|
t.Errorf("Container should be running")
|
|
}
|
|
}
|
|
|
|
|
|
- if _, err = postContainersStart(srv, r, nil, map[string]string{"name": container.Id}); err == nil {
|
|
|
|
|
|
+ r = httptest.NewRecorder()
|
|
|
|
+ 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("A running containter should be able to be started")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1008,20 +1000,15 @@ func TestPostContainersStop(t *testing.T) {
|
|
t.Errorf("Container should be running")
|
|
t.Errorf("Container should be running")
|
|
}
|
|
}
|
|
|
|
|
|
- r := httptest.NewRecorder()
|
|
|
|
-
|
|
|
|
// Note: as it is a POST request, it requires a body.
|
|
// Note: as it is a POST request, it requires a body.
|
|
req, err := http.NewRequest("POST", "/containers/"+container.Id+"/stop?t=1", bytes.NewReader([]byte{}))
|
|
req, err := http.NewRequest("POST", "/containers/"+container.Id+"/stop?t=1", bytes.NewReader([]byte{}))
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- body, err := postContainersStop(srv, r, req, map[string]string{"name": container.Id})
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+ if err := postContainersStop(srv, r, req, map[string]string{"name": container.Id}); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- if body != nil {
|
|
|
|
- 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)
|
|
}
|
|
}
|
|
@@ -1056,12 +1043,12 @@ func TestPostContainersWait(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
setTimeout(t, "Wait timed out", 3*time.Second, func() {
|
|
setTimeout(t, "Wait timed out", 3*time.Second, func() {
|
|
- body, err := postContainersWait(srv, nil, nil, map[string]string{"name": container.Id})
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+ if err := postContainersWait(srv, r, nil, map[string]string{"name": container.Id}); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
apiWait := &ApiWait{}
|
|
apiWait := &ApiWait{}
|
|
- if err := json.Unmarshal(body, apiWait); err != nil {
|
|
|
|
|
|
+ if err := json.Unmarshal(r.Body.Bytes(), apiWait); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if apiWait.StatusCode != 0 {
|
|
if apiWait.StatusCode != 0 {
|
|
@@ -1106,8 +1093,7 @@ func TestPostContainersAttach(t *testing.T) {
|
|
// Attach to it
|
|
// Attach to it
|
|
c1 := make(chan struct{})
|
|
c1 := make(chan struct{})
|
|
go func() {
|
|
go func() {
|
|
- // We're simulating a disconnect so the return value doesn't matter. What matters is the
|
|
|
|
- // fact that CmdAttach returns.
|
|
|
|
|
|
+ defer close(c1)
|
|
|
|
|
|
r := &hijackTester{
|
|
r := &hijackTester{
|
|
ResponseRecorder: httptest.NewRecorder(),
|
|
ResponseRecorder: httptest.NewRecorder(),
|
|
@@ -1120,14 +1106,9 @@ func TestPostContainersAttach(t *testing.T) {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := postContainersAttach(srv, r, req, map[string]string{"name": container.Id})
|
|
|
|
- close(c1)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := postContainersAttach(srv, r, req, map[string]string{"name": container.Id}); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- if body != nil {
|
|
|
|
- t.Fatalf("No body expected, received: %s\n", body)
|
|
|
|
- }
|
|
|
|
}()
|
|
}()
|
|
|
|
|
|
// Acknowledge hijack
|
|
// Acknowledge hijack
|
|
@@ -1165,7 +1146,7 @@ func TestPostContainersAttach(t *testing.T) {
|
|
container.Wait()
|
|
container.Wait()
|
|
}
|
|
}
|
|
|
|
|
|
-// FIXME: Test deleting runnign container
|
|
|
|
|
|
+// FIXME: Test deleting running 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
|
|
func TestDeleteContainers(t *testing.T) {
|
|
func TestDeleteContainers(t *testing.T) {
|
|
@@ -1190,20 +1171,14 @@ func TestDeleteContainers(t *testing.T) {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
- r := httptest.NewRecorder()
|
|
|
|
-
|
|
|
|
req, err := http.NewRequest("DELETE", "/containers/"+container.Id, nil)
|
|
req, err := http.NewRequest("DELETE", "/containers/"+container.Id, nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
-
|
|
|
|
- body, err := deleteContainers(srv, r, req, map[string]string{"name": container.Id})
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ r := httptest.NewRecorder()
|
|
|
|
+ if err := deleteContainers(srv, r, req, map[string]string{"name": container.Id}); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- if body != nil {
|
|
|
|
- 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)
|
|
}
|
|
}
|