summaryrefslogtreecommitdiff
path: root/integration-cli/docker_api_attach_test.go
diff options
context:
space:
mode:
authorAndrew C. Bodine <acbodine@us.ibm.com>2015-01-16 18:52:27 -0800
committerAndrew C. Bodine <acbodine@us.ibm.com>2015-01-21 18:35:51 -0800
commit9e37a04665395cb98687cd09b05ba33736984547 (patch)
tree7ef986dcccbdf4cc5798941dc9743a93869f7c99 /integration-cli/docker_api_attach_test.go
parent3c77e7d63446f0e0b133010fb3731af5556628bb (diff)
downloaddocker-9e37a04665395cb98687cd09b05ba33736984547.tar.gz
Adds test for api attach via websocket
Signed-off-by: Andrew C. Bodine <acbodine@us.ibm.com>
Diffstat (limited to 'integration-cli/docker_api_attach_test.go')
-rw-r--r--integration-cli/docker_api_attach_test.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/integration-cli/docker_api_attach_test.go b/integration-cli/docker_api_attach_test.go
new file mode 100644
index 0000000000..191060dded
--- /dev/null
+++ b/integration-cli/docker_api_attach_test.go
@@ -0,0 +1,66 @@
+package main
+
+import (
+ "bytes"
+ "net"
+ "os/exec"
+ "testing"
+
+ "code.google.com/p/go.net/websocket"
+)
+
+func TestGetContainersAttachWebsocket(t *testing.T) {
+ runCmd := exec.Command(dockerBinary, "run", "-dit", "busybox", "cat")
+ out, _, err := runCommandWithOutput(runCmd)
+ if err != nil {
+ t.Fatalf(out, err)
+ }
+ defer deleteAllContainers()
+
+ rwc, err := net.Dial("unix", "/var/run/docker.sock")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ cleanedContainerID := stripTrailingCharacters(out)
+ config, err := websocket.NewConfig(
+ "/containers/"+cleanedContainerID+"/attach/ws?stream=1&stdin=1&stdout=1&stderr=1",
+ "http://localhost",
+ )
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ ws, err := websocket.NewClient(config, rwc)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer ws.Close()
+
+ expected := []byte("hello")
+ actual := make([]byte, len(expected))
+ outChan := make(chan string)
+ go func() {
+ if _, err := ws.Read(actual); err != nil {
+ t.Fatal(err)
+ }
+ outChan <- "done"
+ }()
+
+ inChan := make(chan string)
+ go func() {
+ if _, err := ws.Write(expected); err != nil {
+ t.Fatal(err)
+ }
+ inChan <- "done"
+ }()
+
+ <-inChan
+ <-outChan
+
+ if !bytes.Equal(expected, actual) {
+ t.Fatal("Expected output on websocket to match input")
+ }
+
+ logDone("container attach websocket - can echo input via cat")
+}