diff options
author | Andy Goldstein <agoldste@redhat.com> | 2016-09-19 14:55:52 -0400 |
---|---|---|
committer | Andy Goldstein <agoldste@redhat.com> | 2016-10-19 11:39:00 -0400 |
commit | fc8097f957ec7ae990f84faf54bce85a399c96af (patch) | |
tree | 93c28b8451b24f48814e4838782678bdc6dcdae5 /integration-cli/docker_api_attach_test.go | |
parent | 15fb3fd9da06c73c4efd88140f6fc12130f361a9 (diff) | |
download | docker-fc8097f957ec7ae990f84faf54bce85a399c96af.tar.gz |
Add Logs to ContainerAttachOptions
Signed-off-by: Andy Goldstein <agoldste@redhat.com>
Diffstat (limited to 'integration-cli/docker_api_attach_test.go')
-rw-r--r-- | integration-cli/docker_api_attach_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/integration-cli/docker_api_attach_test.go b/integration-cli/docker_api_attach_test.go index 740ce6ecdd..d43bf3ab0e 100644 --- a/integration-cli/docker_api_attach_test.go +++ b/integration-cli/docker_api_attach_test.go @@ -2,13 +2,18 @@ package main import ( "bufio" + "bytes" + "context" "io" "net" "net/http" "strings" "time" + "github.com/docker/docker/api/types" + "github.com/docker/docker/client" "github.com/docker/docker/pkg/integration/checker" + "github.com/docker/docker/pkg/stdcopy" "github.com/go-check/check" "golang.org/x/net/websocket" ) @@ -168,4 +173,38 @@ func (s *DockerSuite) TestPostContainersAttach(c *check.C) { // Nothing should be received because both the stdout and stderr of the container will be // sent to the client as stdout when tty is enabled. 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) + + cid, _ = dockerCmd(c, "run", "-di", "busybox", "/bin/sh", "-c", "echo hello; cat") + cid = strings.TrimSpace(cid) + + attachOpts := types.ContainerAttachOptions{ + Stream: true, + Stdin: true, + Stdout: true, + } + + resp, err := client.ContainerAttach(context.Background(), cid, attachOpts) + c.Assert(err, checker.IsNil) + expectSuccess(resp.Conn, resp.Reader, "stdout", false) + + // Make sure we do see "hello" if Logs is true + attachOpts.Logs = true + resp, err = client.ContainerAttach(context.Background(), cid, attachOpts) + c.Assert(err, checker.IsNil) + + defer resp.Conn.Close() + resp.Conn.SetReadDeadline(time.Now().Add(time.Second)) + + _, 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")) } |