Skip to content

Commit

Permalink
Remove testutil.ReadBody
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Nephin <dnephin@docker.com>
  • Loading branch information
dnephin committed Aug 22, 2017
1 parent 6a0105b commit 4f304e7
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 53 deletions.
7 changes: 6 additions & 1 deletion builder/remotecontext/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,16 @@ 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 {
testutil.ErrorContains(t, err, testcase.expectedErr)
}
}
}

func readBody(b io.ReadCloser) ([]byte, error) {
defer b.Close()
return ioutil.ReadAll(b)
}
4 changes: 2 additions & 2 deletions integration-cli/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 1 addition & 2 deletions integration-cli/docker_api_attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 12 additions & 13 deletions integration-cli/docker_api_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}
Expand All @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
13 changes: 6 additions & 7 deletions integration-cli/docker_api_containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions integration-cli/docker_api_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions integration-cli/docker_api_info_test.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions integration-cli/docker_api_session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand All @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions integration-cli/docker_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
4 changes: 2 additions & 2 deletions integration-cli/docker_cli_build_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
1 change: 1 addition & 0 deletions integration-cli/docker_cli_save_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 4f304e7

Please sign in to comment.