зеркало из https://github.com/microsoft/docker.git
Ensure body is closed after error is checked
Signed-off-by: Antonio Murdaca <runcom@linux.com>
This commit is contained in:
Родитель
d593130fda
Коммит
18faf6f94e
|
@ -524,9 +524,10 @@ func (s *DockerSuite) TestBuildApiRemoteTarballContext(c *check.C) {
|
|||
|
||||
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(res.StatusCode, check.Equals, http.StatusOK)
|
||||
b.Close()
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestBuildApiRemoteTarballContextWithCustomDockerfile(c *check.C) {
|
||||
|
@ -1648,9 +1649,10 @@ func (s *DockerSuite) TestPostContainersStartWithoutLinksInHostConfig(c *check.C
|
|||
c.Assert(err, check.IsNil)
|
||||
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(res.StatusCode, check.Equals, http.StatusNoContent)
|
||||
b.Close()
|
||||
}
|
||||
|
||||
// #14640
|
||||
|
@ -1663,9 +1665,10 @@ func (s *DockerSuite) TestPostContainersStartWithLinksInHostConfig(c *check.C) {
|
|||
c.Assert(err, check.IsNil)
|
||||
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(res.StatusCode, check.Equals, http.StatusNoContent)
|
||||
b.Close()
|
||||
}
|
||||
|
||||
// #14640
|
||||
|
@ -1679,7 +1682,8 @@ func (s *DockerSuite) TestPostContainersStartWithLinksInHostConfigIdLinked(c *ch
|
|||
c.Assert(err, check.IsNil)
|
||||
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(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")
|
||||
|
||||
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(status, check.Equals, http.StatusInternalServerError)
|
||||
|
||||
if !bytes.Contains(body, []byte("No exec command 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.Set("filter", filter)
|
||||
status, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
|
||||
c.Assert(status, check.Equals, http.StatusOK)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusOK)
|
||||
|
||||
var images []image
|
||||
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")
|
||||
|
||||
status, _, err := sockRequest("DELETE", "/images/"+id, nil)
|
||||
c.Assert(status, check.Equals, http.StatusConflict)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusConflict)
|
||||
|
||||
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(status, check.Equals, http.StatusNotFound) //Status Codes:404 – no such image
|
||||
|
||||
status, _, err = sockRequest("DELETE", "/images/test:tag1", nil)
|
||||
c.Assert(status, check.Equals, http.StatusOK)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusOK)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestApiImagesHistory(c *check.C) {
|
||||
|
@ -126,8 +126,8 @@ func (s *DockerSuite) TestApiImagesSearchJSONContentType(c *check.C) {
|
|||
testRequires(c, Network)
|
||||
|
||||
res, b, err := sockRequestRaw("GET", "/images/search?term=test", nil, "application/json")
|
||||
b.Close()
|
||||
c.Assert(err, check.IsNil)
|
||||
b.Close()
|
||||
c.Assert(res.StatusCode, check.Equals, http.StatusOK)
|
||||
c.Assert(res.Header.Get("Content-Type"), check.Equals, "application/json")
|
||||
}
|
||||
|
|
|
@ -27,7 +27,16 @@ func (s *DockerSuite) TestLogsApiWithStdout(c *check.C) {
|
|||
|
||||
go func() {
|
||||
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}
|
||||
}()
|
||||
|
||||
|
@ -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), "")
|
||||
t1 := time.Now()
|
||||
c.Assert(err, check.IsNil)
|
||||
body.Close()
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
elapsed := t1.Sub(t0).Seconds()
|
||||
if elapsed > 5.0 {
|
||||
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
|
||||
err = json.NewDecoder(body).Decode(&v)
|
||||
c.Assert(err, check.IsNil)
|
||||
body.Close()
|
||||
|
||||
var cpuPercent = 0.0
|
||||
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)
|
||||
c.Assert(err, check.IsNil)
|
||||
body.Close()
|
||||
|
||||
return st.Network
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@ func (s *DockerSuite) TestApiOptionsRoute(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestApiGetEnabledCors(c *check.C) {
|
||||
res, body, err := sockRequestRaw("GET", "/version", nil, "")
|
||||
body.Close()
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(res.StatusCode, check.Equals, http.StatusOK)
|
||||
body.Close()
|
||||
// TODO: @runcom incomplete tests, why old integration tests had this headers
|
||||
// and here none of the headers below are in the response?
|
||||
//c.Log(res.Header)
|
||||
|
|
Загрузка…
Ссылка в новой задаче