Remove testutil.ReadBody

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-08-21 18:50:40 -04:00
parent 6a0105b452
commit 4f304e72a2
14 changed files with 50 additions and 53 deletions

View File

@ -253,7 +253,7 @@ func TestGetWithStatusError(t *testing.T) {
if testcase.expectedErr == "" {
require.NoError(t, err)
body, err := testutil.ReadBody(response.Body)
body, err := readBody(response.Body)
require.NoError(t, err)
assert.Contains(t, string(body), testcase.expectedBody)
} else {
@ -261,3 +261,8 @@ func TestGetWithStatusError(t *testing.T) {
}
}
}
func readBody(b io.ReadCloser) ([]byte, error) {
defer b.Close()
return ioutil.ReadAll(b)
}

View File

@ -545,7 +545,7 @@ func (d *Daemon) queryRootDir() (string, error) {
}
var b []byte
var i Info
b, err = testutil.ReadBody(body)
b, err = request.ReadBody(body)
if err == nil && resp.StatusCode == http.StatusOK {
// read the docker root dir
if err = json.Unmarshal(b, &i); err == nil {
@ -620,7 +620,7 @@ func (d *Daemon) SockRequest(method, endpoint string, data interface{}) (int, []
if err != nil {
return -1, nil, err
}
b, err := testutil.ReadBody(body)
b, err := request.ReadBody(body)
return res.StatusCode, b, err
}

View File

@ -15,7 +15,6 @@ import (
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/request"
"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/docker/pkg/testutil"
"github.com/go-check/check"
"golang.org/x/net/websocket"
)
@ -80,7 +79,7 @@ func (s *DockerSuite) TestPostContainersAttachContainerNotFound(c *check.C) {
resp, err := client.Do(req)
// connection will shutdown, err should be "persistent connection closed"
c.Assert(resp.StatusCode, checker.Equals, http.StatusNotFound)
content, err := testutil.ReadBody(resp.Body)
content, err := request.ReadBody(resp.Body)
c.Assert(err, checker.IsNil)
expected := "No such container: doesnotexist\r\n"
c.Assert(string(content), checker.Equals, expected)

View File

@ -17,7 +17,6 @@ import (
"github.com/docker/docker/integration-cli/cli/build/fakegit"
"github.com/docker/docker/integration-cli/cli/build/fakestorage"
"github.com/docker/docker/integration-cli/request"
"github.com/docker/docker/pkg/testutil"
"github.com/go-check/check"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/session/filesync"
@ -47,7 +46,7 @@ RUN find /tmp/`
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
buf, err := testutil.ReadBody(body)
buf, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
// Make sure Dockerfile exists.
@ -135,7 +134,7 @@ RUN echo 'right'
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
defer body.Close()
content, err := testutil.ReadBody(body)
content, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
// Build used the wrong dockerfile.
@ -153,7 +152,7 @@ RUN echo from dockerfile`,
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
buf, err := testutil.ReadBody(body)
buf, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
out := string(buf)
@ -174,7 +173,7 @@ RUN echo from Dockerfile`,
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
buf, err := testutil.ReadBody(body)
buf, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
out := string(buf)
@ -196,7 +195,7 @@ RUN echo from dockerfile`,
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
buf, err := testutil.ReadBody(body)
buf, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
out := string(buf)
@ -243,7 +242,7 @@ func (s *DockerSuite) TestBuildAPIUnnormalizedTarPaths(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
out, err := testutil.ReadBody(body)
out, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
lines := strings.Split(string(out), "\n")
c.Assert(len(lines), checker.GreaterThan, 1)
@ -280,7 +279,7 @@ func (s *DockerSuite) TestBuildOnBuildWithCopy(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
out, err := testutil.ReadBody(body)
out, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
c.Assert(string(out), checker.Contains, "Successfully built")
}
@ -299,7 +298,7 @@ func (s *DockerSuite) TestBuildOnBuildCache(c *check.C) {
require.NoError(c, err)
assert.Equal(c, http.StatusOK, res.StatusCode)
out, err := testutil.ReadBody(body)
out, err := request.ReadBody(body)
require.NoError(c, err)
assert.Contains(c, string(out), "Successfully built")
return out
@ -361,7 +360,7 @@ func (s *DockerRegistrySuite) TestBuildCopyFromForcePull(c *check.C) {
require.NoError(c, err)
assert.Equal(c, http.StatusOK, res.StatusCode)
out, err := testutil.ReadBody(body)
out, err := request.ReadBody(body)
require.NoError(c, err)
assert.Contains(c, string(out), "Successfully built")
}
@ -405,7 +404,7 @@ func (s *DockerSuite) TestBuildAddRemoteNoDecompress(c *check.C) {
require.NoError(c, err)
assert.Equal(c, http.StatusOK, res.StatusCode)
out, err := testutil.ReadBody(body)
out, err := request.ReadBody(body)
require.NoError(c, err)
assert.Contains(c, string(out), "Successfully built")
}
@ -461,7 +460,7 @@ func (s *DockerSuite) TestBuildWithSession(c *check.C) {
require.NoError(c, err)
assert.Equal(c, http.StatusOK, res.StatusCode)
outBytes, err := testutil.ReadBody(body)
outBytes, err := request.ReadBody(body)
require.NoError(c, err)
assert.Contains(c, string(outBytes), "Successfully built")
assert.Equal(c, strings.Count(string(outBytes), "Using cache"), 4)
@ -499,7 +498,7 @@ func testBuildWithSession(c *check.C, dir, dockerfile string) (outStr string) {
return err
}
assert.Equal(c, res.StatusCode, http.StatusOK)
out, err := testutil.ReadBody(body)
out, err := request.ReadBody(body)
require.NoError(c, err)
assert.Contains(c, string(out), "Successfully built")
sess.Close()

View File

@ -27,7 +27,6 @@ import (
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/mount"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/testutil"
"github.com/docker/docker/volume"
"github.com/go-check/check"
)
@ -735,7 +734,7 @@ func (s *DockerSuite) TestContainerAPIInvalidPortSyntax(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
b, err := testutil.ReadBody(body)
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
c.Assert(string(b[:]), checker.Contains, "invalid port")
}
@ -755,7 +754,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyInvalidPolicyName(c *check.C)
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
b, err := testutil.ReadBody(body)
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
c.Assert(string(b[:]), checker.Contains, "invalid restart policy")
}
@ -775,7 +774,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyRetryMismatch(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
b, err := testutil.ReadBody(body)
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
c.Assert(string(b[:]), checker.Contains, "maximum retry count cannot be used with restart policy")
}
@ -795,7 +794,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyNegativeRetryCount(c *check.C
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
b, err := testutil.ReadBody(body)
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
c.Assert(string(b[:]), checker.Contains, "maximum retry count cannot be negative")
}
@ -846,7 +845,7 @@ func (s *DockerSuite) TestContainerAPIPostCreateNull(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusCreated)
b, err := testutil.ReadBody(body)
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
type createResp struct {
ID string
@ -875,7 +874,7 @@ func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
res, body, err := request.Post("/containers/create", request.RawString(config), request.JSON)
c.Assert(err, checker.IsNil)
b, err2 := testutil.ReadBody(body)
b, err2 := request.ReadBody(body)
c.Assert(err2, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)

View File

@ -12,7 +12,6 @@ import (
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/request"
"github.com/docker/docker/pkg/testutil"
"github.com/go-check/check"
)
@ -42,7 +41,7 @@ func (s *DockerSuite) TestExecAPICreateNoValidContentType(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
b, err := testutil.ReadBody(body)
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
comment := check.Commentf("Expected message when creating exec command with invalid Content-Type specified")
@ -109,7 +108,7 @@ func (s *DockerSuite) TestExecAPIStartBackwardsCompatible(c *check.C) {
resp, body, err := request.Post(fmt.Sprintf("/v1.20/exec/%s/start", id), request.RawString(`{"Detach": true}`), request.ContentType("text/plain"))
c.Assert(err, checker.IsNil)
b, err := testutil.ReadBody(body)
b, err := request.ReadBody(body)
comment := check.Commentf("response body: %s", b)
c.Assert(err, checker.IsNil, comment)
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK, comment)
@ -144,7 +143,7 @@ func (s *DockerSuite) TestExecAPIStartWithDetach(c *check.C) {
_, body, err := request.Post(fmt.Sprintf("/exec/%s/start", createResp.ID), request.RawString(`{"Detach": true}`), request.JSON)
c.Assert(err, checker.IsNil)
b, err = testutil.ReadBody(body)
b, err = request.ReadBody(body)
comment := check.Commentf("response body: %s", b)
c.Assert(err, checker.IsNil, comment)
@ -207,7 +206,7 @@ func startExec(c *check.C, id string, code int) {
resp, body, err := request.Post(fmt.Sprintf("/exec/%s/start", id), request.RawString(`{"Detach": true}`), request.JSON)
c.Assert(err, checker.IsNil)
b, err := testutil.ReadBody(body)
b, err := request.ReadBody(body)
comment := check.Commentf("response body: %s", b)
c.Assert(err, checker.IsNil, comment)
c.Assert(resp.StatusCode, checker.Equals, code, comment)

View File

@ -1,13 +1,12 @@
package main
import (
"encoding/json"
"net/http"
"encoding/json"
"github.com/docker/docker/api/types"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/request"
"github.com/docker/docker/pkg/testutil"
"github.com/go-check/check"
)
@ -52,7 +51,7 @@ func (s *DockerSuite) TestInfoAPIRuncCommit(c *check.C) {
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
c.Assert(err, checker.IsNil)
b, err := testutil.ReadBody(body)
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
var i types.Info

View File

@ -5,7 +5,6 @@ import (
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/request"
"github.com/docker/docker/pkg/testutil"
"github.com/go-check/check"
)
@ -29,7 +28,7 @@ func (s *DockerSuite) TestSessionCreateWithBadUpgrade(c *check.C) {
res, body, err := request.Post("/session")
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
buf, err := testutil.ReadBody(body)
buf, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
out := string(buf)
@ -41,7 +40,7 @@ func (s *DockerSuite) TestSessionCreateWithBadUpgrade(c *check.C) {
})
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
buf, err = testutil.ReadBody(body)
buf, err = request.ReadBody(body)
c.Assert(err, checker.IsNil)
out = string(buf)

View File

@ -11,7 +11,6 @@ import (
"github.com/docker/docker/api"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/request"
"github.com/docker/docker/pkg/testutil"
"github.com/go-check/check"
)
@ -62,7 +61,7 @@ func (s *DockerSuite) TestAPIErrorJSON(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusBadRequest)
c.Assert(httpResp.Header.Get("Content-Type"), checker.Equals, "application/json")
b, err := testutil.ReadBody(body)
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
c.Assert(getErrorMessage(c, b), checker.Equals, "Config cannot be empty in order to create a container")
}
@ -75,7 +74,7 @@ func (s *DockerSuite) TestAPIErrorPlainText(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusBadRequest)
c.Assert(httpResp.Header.Get("Content-Type"), checker.Contains, "text/plain")
b, err := testutil.ReadBody(body)
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
c.Assert(strings.TrimSpace(string(b)), checker.Equals, "Config cannot be empty in order to create a container")
}
@ -86,7 +85,7 @@ func (s *DockerSuite) TestAPIErrorNotFoundJSON(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusNotFound)
c.Assert(httpResp.Header.Get("Content-Type"), checker.Equals, "application/json")
b, err := testutil.ReadBody(body)
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
c.Assert(getErrorMessage(c, b), checker.Equals, "page not found")
}
@ -96,7 +95,7 @@ func (s *DockerSuite) TestAPIErrorNotFoundPlainText(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusNotFound)
c.Assert(httpResp.Header.Get("Content-Type"), checker.Contains, "text/plain")
b, err := testutil.ReadBody(body)
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
c.Assert(strings.TrimSpace(string(b)), checker.Equals, "page not found")
}

View File

@ -12,15 +12,15 @@ import (
"path/filepath"
"regexp"
"strings"
"time"
"syscall"
"time"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/integration-cli/cli/build"
"github.com/docker/docker/integration-cli/cli/build/fakecontext"
icmd "github.com/docker/docker/pkg/testutil/cmd"
units "github.com/docker/go-units"
"github.com/go-check/check"
)

View File

@ -20,6 +20,7 @@ import (
"github.com/docker/docker/pkg/testutil"
icmd "github.com/docker/docker/pkg/testutil/cmd"
"github.com/go-check/check"
digest "github.com/opencontainers/go-digest"
)
// save a repo using gz compression and try to load it using stdout

View File

@ -151,7 +151,7 @@ func (s *DockerSuite) TestDeprecatedStartWithTooLowMemoryLimit(c *check.C) {
res, body, err := request.Post(formatV123StartAPIURL("/containers/"+containerID+"/start"), request.RawString(config), request.JSON)
c.Assert(err, checker.IsNil)
b, err2 := testutil.ReadBody(body)
b, err2 := request.ReadBody(body)
c.Assert(err2, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
c.Assert(string(b), checker.Contains, "Minimum memory limit allowed is 4MB")

View File

@ -21,7 +21,6 @@ import (
dclient "github.com/docker/docker/client"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/testutil"
"github.com/docker/go-connections/sockets"
"github.com/docker/go-connections/tlsconfig"
"github.com/pkg/errors"
@ -214,10 +213,16 @@ func SockRequest(method, endpoint string, data interface{}, daemon string, modif
if err != nil {
return -1, nil, err
}
b, err := testutil.ReadBody(body)
b, err := ReadBody(body)
return res.StatusCode, b, err
}
// ReadBody read the specified ReadCloser content and returns it
func ReadBody(b io.ReadCloser) ([]byte, error) {
defer b.Close()
return ioutil.ReadAll(b)
}
// SockRequestRaw create a request against the specified host (with method, endpoint and other request modifier) and
// returns the http response, the output as a io.ReadCloser
// Deprecated: use request.Do (or Get, Delete, Post) instead

View File

@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@ -117,9 +116,3 @@ func ParseCgroupPaths(procCgroupData string) map[string]string {
}
return cgroupPaths
}
// ReadBody read the specified ReadCloser content and returns it
func ReadBody(b io.ReadCloser) ([]byte, error) {
defer b.Close()
return ioutil.ReadAll(b)
}