diff options
author | Kir Kolyshkin <kolyshkin@gmail.com> | 2018-03-15 20:07:26 -0700 |
---|---|---|
committer | Kir Kolyshkin <kolyshkin@gmail.com> | 2018-05-03 10:15:48 -0700 |
commit | ecc54889c9a233d558b578dfd48eb5d84506a62a (patch) | |
tree | 124ff514ceb7d59f9f80044e08879820544663dd /integration-cli/docker_api_attach_test.go | |
parent | 7cfd3f4229c82ba61fa13a8818b8ecf58a2dcdbf (diff) | |
download | docker-ecc54889c9a233d558b578dfd48eb5d84506a62a.tar.gz |
TestPostContainerAttach: minor improvements
When this test fails, the error looks like this:
> FAIL: docker_api_attach_test.go:98: DockerSuite.TestPostContainersAttach
> docker_api_attach_test.go:211:
> c.Assert(actualStdout.Bytes(), checker.DeepEquals, []byte("hello\nsuccess"), check.Commentf("Attach didn't return the expected data from stdout"))
> ... obtained []uint8 = []byte{0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73}
> ... expected []uint8 = []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f, 0xa, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73}
> ... Attach didn't return the expected data from stdout
Let's use strings for comparisons to make the output more readable.
While at it,
- get the container's stderr as well, and make sure it's empty;
- check that stdcopy.StdCopy() did not return an error, except for
the timeout which is expected;
- move/remove comments, simplify var names.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Diffstat (limited to 'integration-cli/docker_api_attach_test.go')
-rw-r--r-- | integration-cli/docker_api_attach_test.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/integration-cli/docker_api_attach_test.go b/integration-cli/docker_api_attach_test.go index e191f278f7..bcf890a761 100644 --- a/integration-cli/docker_api_attach_test.go +++ b/integration-cli/docker_api_attach_test.go @@ -18,6 +18,7 @@ import ( "github.com/docker/docker/integration-cli/request" "github.com/docker/docker/pkg/stdcopy" "github.com/go-check/check" + "github.com/pkg/errors" "golang.org/x/net/websocket" ) @@ -176,7 +177,6 @@ func (s *DockerSuite) TestPostContainersAttach(c *check.C) { expectTimeout(conn, br, "stdout") // Test the client API - // Make sure we don't see "hello" if Logs is false client, err := client.NewEnvClient() c.Assert(err, checker.IsNil) defer client.Close() @@ -184,10 +184,13 @@ func (s *DockerSuite) TestPostContainersAttach(c *check.C) { cid, _ = dockerCmd(c, "run", "-di", "busybox", "/bin/sh", "-c", "echo hello; cat") cid = strings.TrimSpace(cid) + // Make sure we don't see "hello" if Logs is false attachOpts := types.ContainerAttachOptions{ Stream: true, Stdin: true, Stdout: true, + Stderr: true, + Logs: false, } resp, err := client.ContainerAttach(context.Background(), cid, attachOpts) @@ -205,10 +208,15 @@ func (s *DockerSuite) TestPostContainersAttach(c *check.C) { _, err = resp.Conn.Write([]byte("success")) c.Assert(err, checker.IsNil) - actualStdout := new(bytes.Buffer) - actualStderr := new(bytes.Buffer) - stdcopy.StdCopy(actualStdout, actualStderr, resp.Reader) - c.Assert(actualStdout.Bytes(), checker.DeepEquals, []byte("hello\nsuccess"), check.Commentf("Attach didn't return the expected data from stdout")) + var outBuf, errBuf bytes.Buffer + _, err = stdcopy.StdCopy(&outBuf, &errBuf, resp.Reader) + if err != nil && errors.Cause(err).(net.Error).Timeout() { + // ignore the timeout error as it is expected + err = nil + } + c.Assert(err, checker.IsNil) + c.Assert(errBuf.String(), checker.Equals, "") + c.Assert(outBuf.String(), checker.Equals, "hello\nsuccess") } // SockRequestHijack creates a connection to specified host (with method, contenttype, …) and returns a hijacked connection |