mirror of https://github.com/docker/docs.git
Merge pull request #14898 from runcom/sockRequestRaw-close-body
Ensure body is closed after error is checked
This commit is contained in:
commit
c2346f6406
|
@ -524,9 +524,10 @@ func (s *DockerSuite) TestBuildApiRemoteTarballContext(c *check.C) {
|
||||||
|
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
res, _, err := sockRequestRaw("POST", "/build?remote="+server.URL()+"/testT.tar", nil, "application/tar")
|
res, b, err := sockRequestRaw("POST", "/build?remote="+server.URL()+"/testT.tar", nil, "application/tar")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
c.Assert(res.StatusCode, check.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, check.Equals, http.StatusOK)
|
||||||
|
b.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestBuildApiRemoteTarballContextWithCustomDockerfile(c *check.C) {
|
func (s *DockerSuite) TestBuildApiRemoteTarballContextWithCustomDockerfile(c *check.C) {
|
||||||
|
@ -1648,9 +1649,10 @@ func (s *DockerSuite) TestPostContainersStartWithoutLinksInHostConfig(c *check.C
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
config := `{"HostConfig":` + hc + `}`
|
config := `{"HostConfig":` + hc + `}`
|
||||||
|
|
||||||
res, _, err := sockRequestRaw("POST", "/containers/"+name+"/start", strings.NewReader(config), "application/json")
|
res, b, err := sockRequestRaw("POST", "/containers/"+name+"/start", strings.NewReader(config), "application/json")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
c.Assert(res.StatusCode, check.Equals, http.StatusNoContent)
|
c.Assert(res.StatusCode, check.Equals, http.StatusNoContent)
|
||||||
|
b.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// #14640
|
// #14640
|
||||||
|
@ -1663,9 +1665,10 @@ func (s *DockerSuite) TestPostContainersStartWithLinksInHostConfig(c *check.C) {
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
config := `{"HostConfig":` + hc + `}`
|
config := `{"HostConfig":` + hc + `}`
|
||||||
|
|
||||||
res, _, err := sockRequestRaw("POST", "/containers/"+name+"/start", strings.NewReader(config), "application/json")
|
res, b, err := sockRequestRaw("POST", "/containers/"+name+"/start", strings.NewReader(config), "application/json")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
c.Assert(res.StatusCode, check.Equals, http.StatusNoContent)
|
c.Assert(res.StatusCode, check.Equals, http.StatusNoContent)
|
||||||
|
b.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// #14640
|
// #14640
|
||||||
|
@ -1679,7 +1682,8 @@ func (s *DockerSuite) TestPostContainersStartWithLinksInHostConfigIdLinked(c *ch
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
config := `{"HostConfig":` + hc + `}`
|
config := `{"HostConfig":` + hc + `}`
|
||||||
|
|
||||||
res, _, err := sockRequestRaw("POST", "/containers/"+name+"/start", strings.NewReader(config), "application/json")
|
res, b, err := sockRequestRaw("POST", "/containers/"+name+"/start", strings.NewReader(config), "application/json")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
c.Assert(res.StatusCode, check.Equals, http.StatusNoContent)
|
c.Assert(res.StatusCode, check.Equals, http.StatusNoContent)
|
||||||
|
b.Close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,8 @@ func (s *DockerSuite) TestExecApiCreateNoCmd(c *check.C) {
|
||||||
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
|
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
|
||||||
|
|
||||||
status, 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})
|
||||||
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||||
|
|
||||||
if !bytes.Contains(body, []byte("No exec command specified")) {
|
if !bytes.Contains(body, []byte("No exec command specified")) {
|
||||||
c.Fatalf("Expected message when creating exec command with no Cmd specified")
|
c.Fatalf("Expected message when creating exec command with no Cmd specified")
|
||||||
|
|
|
@ -22,8 +22,8 @@ func (s *DockerSuite) TestApiImagesFilter(c *check.C) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("filter", filter)
|
v.Set("filter", filter)
|
||||||
status, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
|
status, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
|
||||||
c.Assert(status, check.Equals, http.StatusOK)
|
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
|
|
||||||
var images []image
|
var images []image
|
||||||
if err := json.Unmarshal(b, &images); err != nil {
|
if err := json.Unmarshal(b, &images); err != nil {
|
||||||
|
@ -88,16 +88,16 @@ func (s *DockerSuite) TestApiImagesDelete(c *check.C) {
|
||||||
dockerCmd(c, "tag", name, "test:tag1")
|
dockerCmd(c, "tag", name, "test:tag1")
|
||||||
|
|
||||||
status, _, err := sockRequest("DELETE", "/images/"+id, nil)
|
status, _, err := sockRequest("DELETE", "/images/"+id, nil)
|
||||||
c.Assert(status, check.Equals, http.StatusConflict)
|
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
c.Assert(status, check.Equals, http.StatusConflict)
|
||||||
|
|
||||||
status, _, err = sockRequest("DELETE", "/images/test:noexist", nil)
|
status, _, err = sockRequest("DELETE", "/images/test:noexist", nil)
|
||||||
c.Assert(status, check.Equals, http.StatusNotFound) //Status Codes:404 – no such image
|
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
c.Assert(status, check.Equals, http.StatusNotFound) //Status Codes:404 – no such image
|
||||||
|
|
||||||
status, _, err = sockRequest("DELETE", "/images/test:tag1", nil)
|
status, _, err = sockRequest("DELETE", "/images/test:tag1", nil)
|
||||||
c.Assert(status, check.Equals, http.StatusOK)
|
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
c.Assert(status, check.Equals, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestApiImagesHistory(c *check.C) {
|
func (s *DockerSuite) TestApiImagesHistory(c *check.C) {
|
||||||
|
@ -126,8 +126,8 @@ func (s *DockerSuite) TestApiImagesSearchJSONContentType(c *check.C) {
|
||||||
testRequires(c, Network)
|
testRequires(c, Network)
|
||||||
|
|
||||||
res, b, err := sockRequestRaw("GET", "/images/search?term=test", nil, "application/json")
|
res, b, err := sockRequestRaw("GET", "/images/search?term=test", nil, "application/json")
|
||||||
b.Close()
|
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
b.Close()
|
||||||
c.Assert(res.StatusCode, check.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, check.Equals, http.StatusOK)
|
||||||
c.Assert(res.Header.Get("Content-Type"), check.Equals, "application/json")
|
c.Assert(res.Header.Get("Content-Type"), check.Equals, "application/json")
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,16 @@ func (s *DockerSuite) TestLogsApiWithStdout(c *check.C) {
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
res, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1×tamps=1", id), nil, "")
|
res, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1×tamps=1", id), nil, "")
|
||||||
out, _ := bufio.NewReader(body).ReadString('\n')
|
if err != nil {
|
||||||
|
chLog <- logOut{"", nil, err}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer body.Close()
|
||||||
|
out, err := bufio.NewReader(body).ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
chLog <- logOut{"", nil, err}
|
||||||
|
return
|
||||||
|
}
|
||||||
chLog <- logOut{strings.TrimSpace(out), res, err}
|
chLog <- logOut{strings.TrimSpace(out), res, err}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -65,10 +74,8 @@ func (s *DockerSuite) TestLogsApiFollowEmptyOutput(c *check.C) {
|
||||||
|
|
||||||
_, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name), bytes.NewBuffer(nil), "")
|
_, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name), bytes.NewBuffer(nil), "")
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
body.Close()
|
body.Close()
|
||||||
if err != nil {
|
|
||||||
c.Fatal(err)
|
|
||||||
}
|
|
||||||
elapsed := t1.Sub(t0).Seconds()
|
elapsed := t1.Sub(t0).Seconds()
|
||||||
if elapsed > 5.0 {
|
if elapsed > 5.0 {
|
||||||
c.Fatalf("HTTP response was not immediate (elapsed %.1fs)", elapsed)
|
c.Fatalf("HTTP response was not immediate (elapsed %.1fs)", elapsed)
|
||||||
|
|
|
@ -28,6 +28,7 @@ func (s *DockerSuite) TestCliStatsNoStreamGetCpu(c *check.C) {
|
||||||
var v *types.Stats
|
var v *types.Stats
|
||||||
err = json.NewDecoder(body).Decode(&v)
|
err = json.NewDecoder(body).Decode(&v)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
body.Close()
|
||||||
|
|
||||||
var cpuPercent = 0.0
|
var cpuPercent = 0.0
|
||||||
cpuDelta := float64(v.CpuStats.CpuUsage.TotalUsage - v.PreCpuStats.CpuUsage.TotalUsage)
|
cpuDelta := float64(v.CpuStats.CpuUsage.TotalUsage - v.PreCpuStats.CpuUsage.TotalUsage)
|
||||||
|
@ -113,6 +114,7 @@ func getNetworkStats(c *check.C, id string) types.Network {
|
||||||
|
|
||||||
err = json.NewDecoder(body).Decode(&st)
|
err = json.NewDecoder(body).Decode(&st)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
body.Close()
|
||||||
|
|
||||||
return st.Network
|
return st.Network
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,9 @@ func (s *DockerSuite) TestApiOptionsRoute(c *check.C) {
|
||||||
|
|
||||||
func (s *DockerSuite) TestApiGetEnabledCors(c *check.C) {
|
func (s *DockerSuite) TestApiGetEnabledCors(c *check.C) {
|
||||||
res, body, err := sockRequestRaw("GET", "/version", nil, "")
|
res, body, err := sockRequestRaw("GET", "/version", nil, "")
|
||||||
body.Close()
|
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
c.Assert(res.StatusCode, check.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, check.Equals, http.StatusOK)
|
||||||
|
body.Close()
|
||||||
// TODO: @runcom incomplete tests, why old integration tests had this headers
|
// TODO: @runcom incomplete tests, why old integration tests had this headers
|
||||||
// and here none of the headers below are in the response?
|
// and here none of the headers below are in the response?
|
||||||
//c.Log(res.Header)
|
//c.Log(res.Header)
|
||||||
|
|
Loading…
Reference in New Issue