mirror of
https://github.com/moby/moby.git
synced 2025-08-01 05:47:11 +03:00
Fixing statusCode checks for sockRequest
Signed-off-by: Megan Kostick <mkostick@us.ibm.com>
This commit is contained in:
@ -28,10 +28,9 @@ func (s *DockerSuite) TestContainerApiGetAll(c *check.C) {
|
|||||||
c.Fatalf("Error on container creation: %v, output: %q", err, out)
|
c.Fatalf("Error on container creation: %v, output: %q", err, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatalf("GET all containers sockRequest failed: %v", err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
|
|
||||||
var inspectJSON []struct {
|
var inspectJSON []struct {
|
||||||
Names []string
|
Names []string
|
||||||
@ -57,10 +56,9 @@ func (s *DockerSuite) TestContainerApiGetExport(c *check.C) {
|
|||||||
c.Fatalf("Error on container creation: %v, output: %q", err, out)
|
c.Fatalf("Error on container creation: %v, output: %q", err, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
|
status, body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatalf("GET containers/export sockRequest failed: %v", err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
|
|
||||||
found := false
|
found := false
|
||||||
for tarReader := tar.NewReader(bytes.NewReader(body)); ; {
|
for tarReader := tar.NewReader(bytes.NewReader(body)); ; {
|
||||||
@ -90,10 +88,9 @@ func (s *DockerSuite) TestContainerApiGetChanges(c *check.C) {
|
|||||||
c.Fatalf("Error on container creation: %v, output: %q", err, out)
|
c.Fatalf("Error on container creation: %v, output: %q", err, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
|
status, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatalf("GET containers/changes sockRequest failed: %v", err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
|
|
||||||
changes := []struct {
|
changes := []struct {
|
||||||
Kind int
|
Kind int
|
||||||
@ -122,17 +119,17 @@ func (s *DockerSuite) TestContainerApiStartVolumeBinds(c *check.C) {
|
|||||||
"Volumes": map[string]struct{}{"/tmp": {}},
|
"Volumes": map[string]struct{}{"/tmp": {}},
|
||||||
}
|
}
|
||||||
|
|
||||||
if status, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && status != http.StatusCreated {
|
status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
|
||||||
c.Fatal(err)
|
c.Assert(status, check.Equals, http.StatusCreated)
|
||||||
}
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
bindPath := randomUnixTmpDirPath("test")
|
bindPath := randomUnixTmpDirPath("test")
|
||||||
config = map[string]interface{}{
|
config = map[string]interface{}{
|
||||||
"Binds": []string{bindPath + ":/tmp"},
|
"Binds": []string{bindPath + ":/tmp"},
|
||||||
}
|
}
|
||||||
if status, _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && status != http.StatusNoContent {
|
status, _, err = sockRequest("POST", "/containers/"+name+"/start", config)
|
||||||
c.Fatal(err)
|
c.Assert(status, check.Equals, http.StatusNoContent)
|
||||||
}
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
pth, err := inspectFieldMap(name, "Volumes", "/tmp")
|
pth, err := inspectFieldMap(name, "Volumes", "/tmp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -152,9 +149,9 @@ func (s *DockerSuite) TestContainerApiStartDupVolumeBinds(c *check.C) {
|
|||||||
"Volumes": map[string]struct{}{"/tmp": {}},
|
"Volumes": map[string]struct{}{"/tmp": {}},
|
||||||
}
|
}
|
||||||
|
|
||||||
if status, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && status != http.StatusCreated {
|
status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
|
||||||
c.Fatal(err)
|
c.Assert(status, check.Equals, http.StatusCreated)
|
||||||
}
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
bindPath1 := randomUnixTmpDirPath("test1")
|
bindPath1 := randomUnixTmpDirPath("test1")
|
||||||
bindPath2 := randomUnixTmpDirPath("test2")
|
bindPath2 := randomUnixTmpDirPath("test2")
|
||||||
@ -162,14 +159,15 @@ func (s *DockerSuite) TestContainerApiStartDupVolumeBinds(c *check.C) {
|
|||||||
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 {
|
status, body, err := sockRequest("POST", "/containers/"+name+"/start", config)
|
||||||
c.Fatal("expected container start to fail when duplicate volume binds to same container path")
|
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||||
} else {
|
c.Assert(err, check.IsNil)
|
||||||
if !strings.Contains(string(body), "Duplicate volume") {
|
|
||||||
c.Fatalf("Expected failure due to duplicate bind mounts to same path, instead got: %q with error: %v", string(body), err)
|
if !strings.Contains(string(body), "Duplicate volume") {
|
||||||
}
|
c.Fatalf("Expected failure due to duplicate bind mounts to same path, instead got: %q with error: %v", string(body), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestContainerApiStartVolumesFrom(c *check.C) {
|
func (s *DockerSuite) TestContainerApiStartVolumesFrom(c *check.C) {
|
||||||
volName := "voltst"
|
volName := "voltst"
|
||||||
volPath := "/tmp"
|
volPath := "/tmp"
|
||||||
@ -184,16 +182,16 @@ func (s *DockerSuite) TestContainerApiStartVolumesFrom(c *check.C) {
|
|||||||
"Volumes": map[string]struct{}{volPath: {}},
|
"Volumes": map[string]struct{}{volPath: {}},
|
||||||
}
|
}
|
||||||
|
|
||||||
if status, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && status != http.StatusCreated {
|
status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
|
||||||
c.Fatal(err)
|
c.Assert(status, check.Equals, http.StatusCreated)
|
||||||
}
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
config = map[string]interface{}{
|
config = map[string]interface{}{
|
||||||
"VolumesFrom": []string{volName},
|
"VolumesFrom": []string{volName},
|
||||||
}
|
}
|
||||||
if status, _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && status != http.StatusNoContent {
|
status, _, err = sockRequest("POST", "/containers/"+name+"/start", config)
|
||||||
c.Fatal(err)
|
c.Assert(status, check.Equals, http.StatusNoContent)
|
||||||
}
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
pth, err := inspectFieldMap(name, "Volumes", volPath)
|
pth, err := inspectFieldMap(name, "Volumes", volPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -225,18 +223,18 @@ func (s *DockerSuite) TestVolumesFromHasPriority(c *check.C) {
|
|||||||
"Volumes": map[string]struct{}{volPath: {}},
|
"Volumes": map[string]struct{}{volPath: {}},
|
||||||
}
|
}
|
||||||
|
|
||||||
if status, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && status != http.StatusCreated {
|
status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
|
||||||
c.Fatal(err)
|
c.Assert(status, check.Equals, http.StatusCreated)
|
||||||
}
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
bindPath := randomUnixTmpDirPath("test")
|
bindPath := randomUnixTmpDirPath("test")
|
||||||
config = map[string]interface{}{
|
config = map[string]interface{}{
|
||||||
"VolumesFrom": []string{volName},
|
"VolumesFrom": []string{volName},
|
||||||
"Binds": []string{bindPath + ":/tmp"},
|
"Binds": []string{bindPath + ":/tmp"},
|
||||||
}
|
}
|
||||||
if status, _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && status != http.StatusNoContent {
|
status, _, err = sockRequest("POST", "/containers/"+name+"/start", config)
|
||||||
c.Fatal(err)
|
c.Assert(status, check.Equals, http.StatusNoContent)
|
||||||
}
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
pth, err := inspectFieldMap(name, "Volumes", volPath)
|
pth, err := inspectFieldMap(name, "Volumes", volPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -267,7 +265,9 @@ func (s *DockerSuite) TestGetContainerStats(c *check.C) {
|
|||||||
}
|
}
|
||||||
bc := make(chan b, 1)
|
bc := make(chan b, 1)
|
||||||
go func() {
|
go func() {
|
||||||
_, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
status, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
||||||
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
bc <- b{body, err}
|
bc <- b{body, err}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -309,10 +309,9 @@ func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
|
|||||||
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)
|
status, _, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatal(err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// allow some time to send request and let daemon deal with it
|
// allow some time to send request and let daemon deal with it
|
||||||
@ -340,11 +339,10 @@ func (s *DockerSuite) TestBuildApiDockerfilePath(c *check.C) {
|
|||||||
c.Fatalf("failed to close tar archive: %v", err)
|
c.Fatalf("failed to close tar archive: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, body, err := sockRequestRaw("POST", "/build?dockerfile=../Dockerfile", buffer, "application/x-tar")
|
status, body, err := sockRequestRaw("POST", "/build?dockerfile=../Dockerfile", buffer, "application/x-tar")
|
||||||
if err == nil {
|
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||||
out, _ := readBody(body)
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatalf("Build was supposed to fail: %s", out)
|
|
||||||
}
|
|
||||||
out, err := readBody(body)
|
out, err := readBody(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
@ -367,10 +365,10 @@ RUN find /tmp/`,
|
|||||||
}
|
}
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
_, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json")
|
status, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json")
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatalf("Build failed: %s", err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
buf, err := readBody(body)
|
buf, err := readBody(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
@ -395,11 +393,10 @@ RUN echo from dockerfile`,
|
|||||||
}
|
}
|
||||||
defer git.Close()
|
defer git.Close()
|
||||||
|
|
||||||
_, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
|
status, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
buf, _ := readBody(body)
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatalf("Build failed: %s\n%q", err, buf)
|
|
||||||
}
|
|
||||||
buf, err := readBody(body)
|
buf, err := readBody(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
@ -424,11 +421,10 @@ 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
|
||||||
_, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json")
|
status, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json")
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
buf, _ := readBody(body)
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatalf("Build failed: %s\n%q", err, buf)
|
|
||||||
}
|
|
||||||
buf, err := readBody(body)
|
buf, err := readBody(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
@ -454,10 +450,10 @@ 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
|
||||||
_, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
|
status, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatalf("Build failed: %s", err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
buf, err := readBody(body)
|
buf, err := readBody(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
@ -487,11 +483,10 @@ func (s *DockerSuite) TestBuildApiDockerfileSymlink(c *check.C) {
|
|||||||
c.Fatalf("failed to close tar archive: %v", err)
|
c.Fatalf("failed to close tar archive: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, body, err := sockRequestRaw("POST", "/build", buffer, "application/x-tar")
|
status, body, err := sockRequestRaw("POST", "/build", buffer, "application/x-tar")
|
||||||
if err == nil {
|
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||||
out, _ := readBody(body)
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatalf("Build was supposed to fail: %s", out)
|
|
||||||
}
|
|
||||||
out, err := readBody(body)
|
out, err := readBody(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
@ -524,9 +519,9 @@ func (s *DockerSuite) TestPostContainerBindNormalVolume(c *check.C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}}
|
bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}}
|
||||||
if status, _, err := sockRequest("POST", "/containers/two/start", bindSpec); err != nil && status != http.StatusNoContent {
|
status, _, err := sockRequest("POST", "/containers/two/start", bindSpec)
|
||||||
c.Fatal(err)
|
c.Assert(status, check.Equals, http.StatusNoContent)
|
||||||
}
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
fooDir2, err := inspectFieldMap("two", "Volumes", "/foo")
|
fooDir2, err := inspectFieldMap("two", "Volumes", "/foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -548,9 +543,9 @@ func (s *DockerSuite) TestContainerApiPause(c *check.C) {
|
|||||||
}
|
}
|
||||||
ContainerID := strings.TrimSpace(out)
|
ContainerID := strings.TrimSpace(out)
|
||||||
|
|
||||||
if status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/pause", nil); err != nil && status != http.StatusNoContent {
|
status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/pause", nil)
|
||||||
c.Fatalf("POST a container pause: sockRequest failed: %v", err)
|
c.Assert(status, check.Equals, http.StatusNoContent)
|
||||||
}
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
pausedContainers, err := getSliceOfPausedContainers()
|
pausedContainers, err := getSliceOfPausedContainers()
|
||||||
|
|
||||||
@ -562,9 +557,9 @@ func (s *DockerSuite) TestContainerApiPause(c *check.C) {
|
|||||||
c.Fatalf("there should be one paused container and not %d", len(pausedContainers))
|
c.Fatalf("there should be one paused container and not %d", len(pausedContainers))
|
||||||
}
|
}
|
||||||
|
|
||||||
if status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil); err != nil && status != http.StatusNoContent {
|
status, _, err = sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil)
|
||||||
c.Fatalf("POST a container pause: sockRequest failed: %v", err)
|
c.Assert(status, check.Equals, http.StatusNoContent)
|
||||||
}
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
pausedContainers, err = getSliceOfPausedContainers()
|
pausedContainers, err = getSliceOfPausedContainers()
|
||||||
|
|
||||||
@ -592,10 +587,10 @@ func (s *DockerSuite) TestContainerApiTop(c *check.C) {
|
|||||||
Processes [][]string
|
Processes [][]string
|
||||||
}
|
}
|
||||||
var top topResp
|
var top topResp
|
||||||
_, b, err := sockRequest("GET", "/containers/"+id+"/top?ps_args=aux", nil)
|
status, b, err := sockRequest("GET", "/containers/"+id+"/top?ps_args=aux", nil)
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatal(err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
if err := json.Unmarshal(b, &top); err != nil {
|
if err := json.Unmarshal(b, &top); err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -626,10 +621,9 @@ func (s *DockerSuite) TestContainerApiCommit(c *check.C) {
|
|||||||
id := strings.TrimSpace(string(out))
|
id := strings.TrimSpace(string(out))
|
||||||
|
|
||||||
name := "testcommit" + stringid.GenerateRandomID()
|
name := "testcommit" + stringid.GenerateRandomID()
|
||||||
_, b, err := sockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+id, nil)
|
status, b, err := sockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+id, nil)
|
||||||
if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
|
c.Assert(status, check.Equals, http.StatusCreated)
|
||||||
c.Fatal(err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
|
|
||||||
type resp struct {
|
type resp struct {
|
||||||
Id string
|
Id string
|
||||||
@ -660,10 +654,10 @@ func (s *DockerSuite) TestContainerApiCreate(c *check.C) {
|
|||||||
"Cmd": []string{"/bin/sh", "-c", "touch /test && ls /test"},
|
"Cmd": []string{"/bin/sh", "-c", "touch /test && ls /test"},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, b, err := sockRequest("POST", "/containers/create", config)
|
status, b, err := sockRequest("POST", "/containers/create", config)
|
||||||
if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
|
c.Assert(status, check.Equals, http.StatusCreated)
|
||||||
c.Fatal(err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
type createResp struct {
|
type createResp struct {
|
||||||
Id string
|
Id string
|
||||||
}
|
}
|
||||||
@ -736,26 +730,21 @@ func (s *DockerSuite) TestContainerApiVerifyHeader(c *check.C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try with no content-type
|
// Try with no content-type
|
||||||
_, body, err := create("")
|
status, body, err := create("")
|
||||||
if err == nil {
|
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||||
b, _ := readBody(body)
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatalf("expected error when content-type is not set: %q", string(b))
|
|
||||||
}
|
|
||||||
body.Close()
|
body.Close()
|
||||||
|
|
||||||
// Try with wrong content-type
|
// Try with wrong content-type
|
||||||
_, body, err = create("application/xml")
|
status, body, err = create("application/xml")
|
||||||
if err == nil {
|
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||||
b, _ := readBody(body)
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatalf("expected error when content-type is not set: %q", string(b))
|
|
||||||
}
|
|
||||||
body.Close()
|
body.Close()
|
||||||
|
|
||||||
// now application/json
|
// now application/json
|
||||||
_, body, err = create("application/json")
|
status, body, err = create("application/json")
|
||||||
if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
|
c.Assert(status, check.Equals, http.StatusCreated)
|
||||||
b, _ := readBody(body)
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatalf("%v - %q", err, string(b))
|
|
||||||
}
|
|
||||||
body.Close()
|
body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -786,11 +775,9 @@ func (s *DockerSuite) TestContainerApiPostCreateNull(c *check.C) {
|
|||||||
"NetworkDisabled":false,
|
"NetworkDisabled":false,
|
||||||
"OnBuild":null}`
|
"OnBuild":null}`
|
||||||
|
|
||||||
_, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
status, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
||||||
if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
|
c.Assert(status, check.Equals, http.StatusCreated)
|
||||||
b, _ := readBody(body)
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatal(err, string(b))
|
|
||||||
}
|
|
||||||
|
|
||||||
b, err := readBody(body)
|
b, err := readBody(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -822,16 +809,14 @@ func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
|
|||||||
"Memory": 524287
|
"Memory": 524287
|
||||||
}`
|
}`
|
||||||
|
|
||||||
_, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
status, body, _ := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
||||||
b, err2 := readBody(body)
|
b, err2 := readBody(body)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
c.Fatal(err2)
|
c.Fatal(err2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil || !strings.Contains(string(b), "Minimum memory limit allowed is 4MB") {
|
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||||
c.Errorf("Memory limit is smaller than the allowed limit. Container creation should've failed!")
|
c.Assert(strings.Contains(string(b), "Minimum memory limit allowed is 4MB"), check.Equals, true)
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) {
|
func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) {
|
||||||
@ -847,13 +832,12 @@ func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) {
|
|||||||
"Memory": 524287
|
"Memory": 524287
|
||||||
}`
|
}`
|
||||||
|
|
||||||
_, body, err := sockRequestRaw("POST", "/containers/"+containerID+"/start", strings.NewReader(config), "application/json")
|
status, body, _ := sockRequestRaw("POST", "/containers/"+containerID+"/start", strings.NewReader(config), "application/json")
|
||||||
b, err2 := readBody(body)
|
b, err2 := readBody(body)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
c.Fatal(err2)
|
c.Fatal(err2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil || !strings.Contains(string(b), "Minimum memory limit allowed is 4MB") {
|
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||||
c.Errorf("Memory limit is smaller than the allowed limit. Container creation should've failed!")
|
c.Assert(strings.Contains(string(b), "Minimum memory limit allowed is 4MB"), check.Equals, true)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,6 @@ func (s *DockerSuite) TestExecResizeApiHeightWidthNoInt(c *check.C) {
|
|||||||
|
|
||||||
endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar"
|
endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar"
|
||||||
status, _, err := sockRequest("POST", endpoint, nil)
|
status, _, err := sockRequest("POST", endpoint, nil)
|
||||||
if err == nil {
|
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||||
c.Fatal("Expected exec resize Request to fail")
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
if status != http.StatusInternalServerError {
|
|
||||||
c.Fatalf("Status expected %d, got %d", http.StatusInternalServerError, status)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
@ -18,8 +19,11 @@ func (s *DockerSuite) TestExecApiCreateNoCmd(c *check.C) {
|
|||||||
c.Fatal(out, err)
|
c.Fatal(out, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil})
|
status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil})
|
||||||
if err == nil || !bytes.Contains(body, []byte("No exec command specified")) {
|
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||||
c.Fatalf("Expected error when creating exec command with no Cmd specified: %q", err)
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
|
if !bytes.Contains(body, []byte("No exec command specified")) {
|
||||||
|
c.Fatalf("Expected message when creating exec command with no Cmd specified")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
@ -11,10 +12,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (s *DockerSuite) TestLegacyImages(c *check.C) {
|
func (s *DockerSuite) TestLegacyImages(c *check.C) {
|
||||||
_, body, err := sockRequest("GET", "/v1.6/images/json", nil)
|
status, body, err := sockRequest("GET", "/v1.6/images/json", nil)
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatalf("Error on GET: %s", err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
|
|
||||||
images := []types.LegacyImage{}
|
images := []types.LegacyImage{}
|
||||||
if err = json.Unmarshal(body, &images); err != nil {
|
if err = json.Unmarshal(body, &images); err != nil {
|
||||||
@ -40,10 +40,10 @@ func (s *DockerSuite) TestApiImagesFilter(c *check.C) {
|
|||||||
getImages := func(filter string) []image {
|
getImages := func(filter string) []image {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("filter", filter)
|
v.Set("filter", filter)
|
||||||
_, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
|
status, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatal(err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
var images []image
|
var images []image
|
||||||
if err := json.Unmarshal(b, &images); err != nil {
|
if err := json.Unmarshal(b, &images); err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
@ -76,20 +76,20 @@ func (s *DockerSuite) TestApiImagesSaveAndLoad(c *check.C) {
|
|||||||
id := strings.TrimSpace(out)
|
id := strings.TrimSpace(out)
|
||||||
defer deleteImages("saveandload")
|
defer deleteImages("saveandload")
|
||||||
|
|
||||||
_, body, err := sockRequestRaw("GET", "/images/"+id+"/get", nil, "")
|
status, body, err := sockRequestRaw("GET", "/images/"+id+"/get", nil, "")
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatal(err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
defer body.Close()
|
defer body.Close()
|
||||||
|
|
||||||
if out, err := exec.Command(dockerBinary, "rmi", id).CombinedOutput(); err != nil {
|
if out, err := exec.Command(dockerBinary, "rmi", id).CombinedOutput(); err != nil {
|
||||||
c.Fatal(err, out)
|
c.Fatal(err, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar")
|
status, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar")
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatal(err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
defer loadBody.Close()
|
defer loadBody.Close()
|
||||||
|
|
||||||
inspectOut, err := exec.Command(dockerBinary, "inspect", "--format='{{ .Id }}'", id).CombinedOutput()
|
inspectOut, err := exec.Command(dockerBinary, "inspect", "--format='{{ .Id }}'", id).CombinedOutput()
|
||||||
|
@ -10,10 +10,9 @@ import (
|
|||||||
func (s *DockerSuite) TestInfoApi(c *check.C) {
|
func (s *DockerSuite) TestInfoApi(c *check.C) {
|
||||||
endpoint := "/info"
|
endpoint := "/info"
|
||||||
|
|
||||||
statusCode, body, err := sockRequest("GET", endpoint, nil)
|
status, body, err := sockRequest("GET", endpoint, nil)
|
||||||
if err != nil || statusCode != http.StatusOK {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatalf("Expected %d from info request, got %d", http.StatusOK, statusCode)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
|
|
||||||
// always shown fields
|
// always shown fields
|
||||||
stringsToCheck := []string{
|
stringsToCheck := []string{
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -26,10 +27,9 @@ func (s *DockerSuite) TestInspectApiContainerResponse(c *check.C) {
|
|||||||
if testVersion != "latest" {
|
if testVersion != "latest" {
|
||||||
endpoint = "/" + testVersion + endpoint
|
endpoint = "/" + testVersion + endpoint
|
||||||
}
|
}
|
||||||
_, body, err := sockRequest("GET", endpoint, nil)
|
status, body, err := sockRequest("GET", endpoint, nil)
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatalf("sockRequest failed for %s version: %v", testVersion, err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
|
|
||||||
var inspectJSON map[string]interface{}
|
var inspectJSON map[string]interface{}
|
||||||
if err = json.Unmarshal(body, &inspectJSON); err != nil {
|
if err = json.Unmarshal(body, &inspectJSON); err != nil {
|
||||||
|
@ -17,11 +17,9 @@ func (s *DockerSuite) TestLogsApiWithStdout(c *check.C) {
|
|||||||
c.Fatal(out, err)
|
c.Fatal(out, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
statusCode, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1×tamps=1", name), nil)
|
status, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1×tamps=1", name), nil)
|
||||||
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
if err != nil || statusCode != http.StatusOK {
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatalf("Expected %d from logs request, got %d", http.StatusOK, statusCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !bytes.Contains(body, []byte(name)) {
|
if !bytes.Contains(body, []byte(name)) {
|
||||||
c.Fatalf("Expected %s, got %s", name, string(body[:]))
|
c.Fatalf("Expected %s, got %s", name, string(body[:]))
|
||||||
@ -35,11 +33,9 @@ func (s *DockerSuite) TestLogsApiNoStdoutNorStderr(c *check.C) {
|
|||||||
c.Fatal(out, err)
|
c.Fatal(out, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
statusCode, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil)
|
status, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil)
|
||||||
|
c.Assert(status, check.Equals, http.StatusBadRequest)
|
||||||
if err == nil || statusCode != http.StatusBadRequest {
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatalf("Expected %d from logs request, got %d", http.StatusBadRequest, statusCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
expected := "Bad parameters: you must choose at least one stream"
|
expected := "Bad parameters: you must choose at least one stream"
|
||||||
if !bytes.Contains(body, []byte(expected)) {
|
if !bytes.Contains(body, []byte(expected)) {
|
||||||
|
@ -17,10 +17,9 @@ func (s *DockerSuite) TestResizeApiResponse(c *check.C) {
|
|||||||
cleanedContainerID := strings.TrimSpace(out)
|
cleanedContainerID := strings.TrimSpace(out)
|
||||||
|
|
||||||
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
|
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
|
||||||
_, _, err = sockRequest("POST", endpoint, nil)
|
status, _, err := sockRequest("POST", endpoint, nil)
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatalf("resize Request failed %v", err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
|
func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
|
||||||
@ -33,12 +32,8 @@ func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
|
|||||||
|
|
||||||
endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar"
|
endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar"
|
||||||
status, _, err := sockRequest("POST", endpoint, nil)
|
status, _, err := sockRequest("POST", endpoint, nil)
|
||||||
if err == nil {
|
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||||
c.Fatal("Expected resize Request to fail")
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
if status != http.StatusInternalServerError {
|
|
||||||
c.Fatalf("Status expected %d, got %d", http.StatusInternalServerError, status)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
|
func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
|
||||||
@ -57,10 +52,10 @@ func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
|
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
|
||||||
_, body, err := sockRequest("POST", endpoint, nil)
|
status, body, err := sockRequest("POST", endpoint, nil)
|
||||||
if err == nil {
|
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||||
c.Fatalf("resize should fail when container is not started")
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
|
if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
|
||||||
c.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
|
c.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/autogen/dockerversion"
|
"github.com/docker/docker/autogen/dockerversion"
|
||||||
@ -9,10 +10,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (s *DockerSuite) TestGetVersion(c *check.C) {
|
func (s *DockerSuite) TestGetVersion(c *check.C) {
|
||||||
_, body, err := sockRequest("GET", "/version", nil)
|
status, body, err := sockRequest("GET", "/version", nil)
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatal(err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
var v types.Version
|
var v types.Version
|
||||||
if err := json.Unmarshal(body, &v); err != nil {
|
if err := json.Unmarshal(body, &v); err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
|
@ -60,13 +60,8 @@ func (s *DockerSuite) TestRmRunningContainerCheckError409(c *check.C) {
|
|||||||
|
|
||||||
endpoint := "/containers/foo"
|
endpoint := "/containers/foo"
|
||||||
status, _, err := sockRequest("DELETE", endpoint, nil)
|
status, _, err := sockRequest("DELETE", endpoint, nil)
|
||||||
|
c.Assert(status, check.Equals, http.StatusConflict)
|
||||||
if err == nil {
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatalf("Expected error, can't rm a running container")
|
|
||||||
} else if status != http.StatusConflict {
|
|
||||||
c.Fatalf("Expected error to contain '409 Conflict' but found %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestRmForceRemoveRunningContainer(c *check.C) {
|
func (s *DockerSuite) TestRmForceRemoveRunningContainer(c *check.C) {
|
||||||
|
@ -350,9 +350,6 @@ func sockRequestRaw(method, endpoint string, data io.Reader, ct string) (int, io
|
|||||||
defer client.Close()
|
defer client.Close()
|
||||||
return resp.Body.Close()
|
return resp.Body.Close()
|
||||||
})
|
})
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
return resp.StatusCode, body, fmt.Errorf("received status != 200 OK: %s", resp.Status)
|
|
||||||
}
|
|
||||||
|
|
||||||
return resp.StatusCode, body, err
|
return resp.StatusCode, body, err
|
||||||
}
|
}
|
||||||
@ -1062,10 +1059,9 @@ func daemonTime(c *check.C) time.Time {
|
|||||||
return time.Now()
|
return time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
_, body, err := sockRequest("GET", "/info", nil)
|
status, body, err := sockRequest("GET", "/info", nil)
|
||||||
if err != nil {
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
c.Fatalf("daemonTime: failed to get /info: %v", err)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
|
||||||
|
|
||||||
type infoJSON struct {
|
type infoJSON struct {
|
||||||
SystemTime string
|
SystemTime string
|
||||||
|
@ -58,8 +58,8 @@ var (
|
|||||||
func() bool {
|
func() bool {
|
||||||
if daemonExecDriver == "" {
|
if daemonExecDriver == "" {
|
||||||
// get daemon info
|
// get daemon info
|
||||||
_, body, err := sockRequest("GET", "/info", nil)
|
status, body, err := sockRequest("GET", "/info", nil)
|
||||||
if err != nil {
|
if err != nil || status != http.StatusOK {
|
||||||
log.Fatalf("sockRequest failed for /info: %v", err)
|
log.Fatalf("sockRequest failed for /info: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user