|
@@ -3,14 +3,15 @@ package main
|
|
import (
|
|
import (
|
|
"bytes"
|
|
"bytes"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
- "github.com/docker/docker/api/types"
|
|
|
|
- "github.com/docker/docker/pkg/stringid"
|
|
|
|
- "github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
|
|
|
|
"io"
|
|
"io"
|
|
"os/exec"
|
|
"os/exec"
|
|
"strings"
|
|
"strings"
|
|
"testing"
|
|
"testing"
|
|
"time"
|
|
"time"
|
|
|
|
+
|
|
|
|
+ "github.com/docker/docker/api/types"
|
|
|
|
+ "github.com/docker/docker/pkg/stringid"
|
|
|
|
+ "github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
|
|
)
|
|
)
|
|
|
|
|
|
func TestContainerApiGetAll(t *testing.T) {
|
|
func TestContainerApiGetAll(t *testing.T) {
|
|
@@ -28,7 +29,7 @@ func TestContainerApiGetAll(t *testing.T) {
|
|
t.Fatalf("Error on container creation: %v, output: %q", err, out)
|
|
t.Fatalf("Error on container creation: %v, output: %q", err, out)
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
|
|
|
|
|
+ _, body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatalf("GET all containers sockRequest failed: %v", err)
|
|
t.Fatalf("GET all containers sockRequest failed: %v", err)
|
|
}
|
|
}
|
|
@@ -61,7 +62,7 @@ func TestContainerApiGetExport(t *testing.T) {
|
|
t.Fatalf("Error on container creation: %v, output: %q", err, out)
|
|
t.Fatalf("Error on container creation: %v, output: %q", err, out)
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
|
|
|
|
|
|
+ _, body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatalf("GET containers/export sockRequest failed: %v", err)
|
|
t.Fatalf("GET containers/export sockRequest failed: %v", err)
|
|
}
|
|
}
|
|
@@ -98,7 +99,7 @@ func TestContainerApiGetChanges(t *testing.T) {
|
|
t.Fatalf("Error on container creation: %v, output: %q", err, out)
|
|
t.Fatalf("Error on container creation: %v, output: %q", err, out)
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
|
|
|
|
|
|
+ _, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatalf("GET containers/changes sockRequest failed: %v", err)
|
|
t.Fatalf("GET containers/changes sockRequest failed: %v", err)
|
|
}
|
|
}
|
|
@@ -133,7 +134,7 @@ func TestContainerApiStartVolumeBinds(t *testing.T) {
|
|
"Volumes": map[string]struct{}{"/tmp": {}},
|
|
"Volumes": map[string]struct{}{"/tmp": {}},
|
|
}
|
|
}
|
|
|
|
|
|
- if _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
|
|
|
|
|
|
+ if _, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -141,7 +142,7 @@ func TestContainerApiStartVolumeBinds(t *testing.T) {
|
|
config = map[string]interface{}{
|
|
config = map[string]interface{}{
|
|
"Binds": []string{bindPath + ":/tmp"},
|
|
"Binds": []string{bindPath + ":/tmp"},
|
|
}
|
|
}
|
|
- if _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && !strings.Contains(err.Error(), "204 No Content") {
|
|
|
|
|
|
+ if _, _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && !strings.Contains(err.Error(), "204 No Content") {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -166,7 +167,7 @@ func TestContainerApiStartDupVolumeBinds(t *testing.T) {
|
|
"Volumes": map[string]struct{}{"/tmp": {}},
|
|
"Volumes": map[string]struct{}{"/tmp": {}},
|
|
}
|
|
}
|
|
|
|
|
|
- if _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
|
|
|
|
|
|
+ if _, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -176,7 +177,7 @@ func TestContainerApiStartDupVolumeBinds(t *testing.T) {
|
|
config = map[string]interface{}{
|
|
config = map[string]interface{}{
|
|
"Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"},
|
|
"Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"},
|
|
}
|
|
}
|
|
- if body, err := sockRequest("POST", "/containers/"+name+"/start", config); err == nil {
|
|
|
|
|
|
+ if _, body, err := sockRequest("POST", "/containers/"+name+"/start", config); err == nil {
|
|
t.Fatal("expected container start to fail when duplicate volume binds to same container path")
|
|
t.Fatal("expected container start to fail when duplicate volume binds to same container path")
|
|
} else {
|
|
} else {
|
|
if !strings.Contains(string(body), "Duplicate volume") {
|
|
if !strings.Contains(string(body), "Duplicate volume") {
|
|
@@ -201,14 +202,14 @@ func TestContainerApiStartVolumesFrom(t *testing.T) {
|
|
"Volumes": map[string]struct{}{volPath: {}},
|
|
"Volumes": map[string]struct{}{volPath: {}},
|
|
}
|
|
}
|
|
|
|
|
|
- if _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
|
|
|
|
|
|
+ if _, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
config = map[string]interface{}{
|
|
config = map[string]interface{}{
|
|
"VolumesFrom": []string{volName},
|
|
"VolumesFrom": []string{volName},
|
|
}
|
|
}
|
|
- if _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && !strings.Contains(err.Error(), "204 No Content") {
|
|
|
|
|
|
+ if _, _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && !strings.Contains(err.Error(), "204 No Content") {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -245,7 +246,7 @@ func TestVolumesFromHasPriority(t *testing.T) {
|
|
"Volumes": map[string]struct{}{volPath: {}},
|
|
"Volumes": map[string]struct{}{volPath: {}},
|
|
}
|
|
}
|
|
|
|
|
|
- if _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
|
|
|
|
|
|
+ if _, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -254,7 +255,7 @@ func TestVolumesFromHasPriority(t *testing.T) {
|
|
"VolumesFrom": []string{volName},
|
|
"VolumesFrom": []string{volName},
|
|
"Binds": []string{bindPath + ":/tmp"},
|
|
"Binds": []string{bindPath + ":/tmp"},
|
|
}
|
|
}
|
|
- if _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && !strings.Contains(err.Error(), "204 No Content") {
|
|
|
|
|
|
+ if _, _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && !strings.Contains(err.Error(), "204 No Content") {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -290,7 +291,7 @@ func TestGetContainerStats(t *testing.T) {
|
|
}
|
|
}
|
|
bc := make(chan b, 1)
|
|
bc := make(chan b, 1)
|
|
go func() {
|
|
go func() {
|
|
- body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
|
|
|
|
|
+ _, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
|
bc <- b{body, err}
|
|
bc <- b{body, err}
|
|
}()
|
|
}()
|
|
|
|
|
|
@@ -334,7 +335,7 @@ func TestGetStoppedContainerStats(t *testing.T) {
|
|
go func() {
|
|
go func() {
|
|
// We'll never get return for GET stats from sockRequest as of now,
|
|
// We'll never get return for GET stats from sockRequest as of now,
|
|
// just send request and see if panic or error would happen on daemon side.
|
|
// just send request and see if panic or error would happen on daemon side.
|
|
- _, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
|
|
|
|
|
+ _, _, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
@@ -367,7 +368,7 @@ func TestBuildApiDockerfilePath(t *testing.T) {
|
|
t.Fatalf("failed to close tar archive: %v", err)
|
|
t.Fatalf("failed to close tar archive: %v", err)
|
|
}
|
|
}
|
|
|
|
|
|
- out, err := sockRequestRaw("POST", "/build?dockerfile=../Dockerfile", buffer, "application/x-tar")
|
|
|
|
|
|
+ _, out, err := sockRequestRaw("POST", "/build?dockerfile=../Dockerfile", buffer, "application/x-tar")
|
|
if err == nil {
|
|
if err == nil {
|
|
t.Fatalf("Build was supposed to fail: %s", out)
|
|
t.Fatalf("Build was supposed to fail: %s", out)
|
|
}
|
|
}
|
|
@@ -391,7 +392,7 @@ RUN find /tmp/`,
|
|
}
|
|
}
|
|
defer server.Close()
|
|
defer server.Close()
|
|
|
|
|
|
- buf, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json")
|
|
|
|
|
|
+ _, buf, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json")
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatalf("Build failed: %s", err)
|
|
t.Fatalf("Build failed: %s", err)
|
|
}
|
|
}
|
|
@@ -417,7 +418,7 @@ RUN echo from dockerfile`,
|
|
}
|
|
}
|
|
defer git.Close()
|
|
defer git.Close()
|
|
|
|
|
|
- buf, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
|
|
|
|
|
|
+ _, buf, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatalf("Build failed: %s\n%q", err, buf)
|
|
t.Fatalf("Build failed: %s\n%q", err, buf)
|
|
}
|
|
}
|
|
@@ -443,7 +444,7 @@ RUN echo from Dockerfile`,
|
|
defer git.Close()
|
|
defer git.Close()
|
|
|
|
|
|
// Make sure it tries to 'dockerfile' query param value
|
|
// Make sure it tries to 'dockerfile' query param value
|
|
- buf, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json")
|
|
|
|
|
|
+ _, buf, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json")
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatalf("Build failed: %s\n%q", err, buf)
|
|
t.Fatalf("Build failed: %s\n%q", err, buf)
|
|
}
|
|
}
|
|
@@ -470,7 +471,7 @@ RUN echo from dockerfile`,
|
|
defer git.Close()
|
|
defer git.Close()
|
|
|
|
|
|
// Make sure it tries to 'dockerfile' query param value
|
|
// Make sure it tries to 'dockerfile' query param value
|
|
- buf, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
|
|
|
|
|
|
+ _, buf, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatalf("Build failed: %s", err)
|
|
t.Fatalf("Build failed: %s", err)
|
|
}
|
|
}
|
|
@@ -501,7 +502,7 @@ func TestBuildApiDockerfileSymlink(t *testing.T) {
|
|
t.Fatalf("failed to close tar archive: %v", err)
|
|
t.Fatalf("failed to close tar archive: %v", err)
|
|
}
|
|
}
|
|
|
|
|
|
- out, err := sockRequestRaw("POST", "/build", buffer, "application/x-tar")
|
|
|
|
|
|
+ _, out, err := sockRequestRaw("POST", "/build", buffer, "application/x-tar")
|
|
if err == nil {
|
|
if err == nil {
|
|
t.Fatalf("Build was supposed to fail: %s", out)
|
|
t.Fatalf("Build was supposed to fail: %s", out)
|
|
}
|
|
}
|
|
@@ -537,7 +538,7 @@ func TestPostContainerBindNormalVolume(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}}
|
|
bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}}
|
|
- _, err = sockRequest("POST", "/containers/two/start", bindSpec)
|
|
|
|
|
|
+ _, _, err = sockRequest("POST", "/containers/two/start", bindSpec)
|
|
if err != nil && !strings.Contains(err.Error(), "204 No Content") {
|
|
if err != nil && !strings.Contains(err.Error(), "204 No Content") {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
@@ -565,7 +566,7 @@ func TestContainerApiPause(t *testing.T) {
|
|
}
|
|
}
|
|
ContainerID := strings.TrimSpace(out)
|
|
ContainerID := strings.TrimSpace(out)
|
|
|
|
|
|
- if _, err = sockRequest("POST", "/containers/"+ContainerID+"/pause", nil); err != nil && !strings.Contains(err.Error(), "204 No Content") {
|
|
|
|
|
|
+ if _, _, err = sockRequest("POST", "/containers/"+ContainerID+"/pause", nil); err != nil && !strings.Contains(err.Error(), "204 No Content") {
|
|
t.Fatalf("POST a container pause: sockRequest failed: %v", err)
|
|
t.Fatalf("POST a container pause: sockRequest failed: %v", err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -579,7 +580,7 @@ func TestContainerApiPause(t *testing.T) {
|
|
t.Fatalf("there should be one paused container and not %d", len(pausedContainers))
|
|
t.Fatalf("there should be one paused container and not %d", len(pausedContainers))
|
|
}
|
|
}
|
|
|
|
|
|
- if _, err = sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil); err != nil && !strings.Contains(err.Error(), "204 No Content") {
|
|
|
|
|
|
+ if _, _, err = sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil); err != nil && !strings.Contains(err.Error(), "204 No Content") {
|
|
t.Fatalf("POST a container pause: sockRequest failed: %v", err)
|
|
t.Fatalf("POST a container pause: sockRequest failed: %v", err)
|
|
}
|
|
}
|
|
|
|
|