summaryrefslogtreecommitdiff
path: root/integration-cli/docker_api_attach_test.go
diff options
context:
space:
mode:
authorAndy Goldstein <agoldste@redhat.com>2016-09-19 14:55:52 -0400
committerAndy Goldstein <agoldste@redhat.com>2016-10-19 11:39:00 -0400
commitfc8097f957ec7ae990f84faf54bce85a399c96af (patch)
tree93c28b8451b24f48814e4838782678bdc6dcdae5 /integration-cli/docker_api_attach_test.go
parent15fb3fd9da06c73c4efd88140f6fc12130f361a9 (diff)
downloaddocker-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.go39
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"))
}