moby/integration-cli/docker_api_attach_test.go
Ahmet Alp Balkan ac6cb41d52 docker_api_attach_test: fix WS test to use DOCKER_TEST_HOST if specified
TestGetContainersAttachWebsocket is currently broken on Windows CI tests
b/c it has hardcoded unix://var/run/docker.sock.  This change makes use
of @icecrime's code in docker_utils and generalizes it with sockConn()
to provide a net.Conn by making use of DOCKER_TEST_HOST. Also fixes
the test.

Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
2015-02-12 15:11:19 -08:00

66 lines
1.3 KiB
Go

package main
import (
"bytes"
"os/exec"
"testing"
"time"
"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 := sockConn(time.Duration(10 * time.Second))
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")
}