1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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>
This commit is contained in:
Ahmet Alp Balkan 2015-02-12 11:51:28 -08:00
parent d8f60a6cf7
commit ac6cb41d52
2 changed files with 22 additions and 18 deletions

View file

@ -2,9 +2,9 @@ package main
import (
"bytes"
"net"
"os/exec"
"testing"
"time"
"code.google.com/p/go.net/websocket"
)
@ -17,7 +17,7 @@ func TestGetContainersAttachWebsocket(t *testing.T) {
}
defer deleteAllContainers()
rwc, err := net.Dial("unix", "/var/run/docker.sock")
rwc, err := sockConn(time.Duration(10 * time.Second))
if err != nil {
t.Fatal(err)
}

View file

@ -273,6 +273,24 @@ func daemonHost() string {
return daemonUrlStr
}
func sockConn(timeout time.Duration) (net.Conn, error) {
daemon := daemonHost()
daemonUrl, err := url.Parse(daemon)
if err != nil {
return nil, fmt.Errorf("could not parse url %q: %v", daemon, err)
}
var c net.Conn
switch daemonUrl.Scheme {
case "unix":
return net.DialTimeout(daemonUrl.Scheme, daemonUrl.Path, timeout)
case "tcp":
return net.DialTimeout(daemonUrl.Scheme, daemonUrl.Host, timeout)
default:
return c, fmt.Errorf("unknown scheme %v (%s)", daemonUrl.Scheme, daemon)
}
}
func sockRequest(method, endpoint string, data interface{}) ([]byte, error) {
jsonData := bytes.NewBuffer(nil)
if err := json.NewEncoder(jsonData).Encode(data); err != nil {
@ -283,23 +301,9 @@ func sockRequest(method, endpoint string, data interface{}) ([]byte, error) {
}
func sockRequestRaw(method, endpoint string, data io.Reader, ct string) ([]byte, error) {
daemon := daemonHost()
daemonUrl, err := url.Parse(daemon)
c, err := sockConn(time.Duration(10 * time.Second))
if err != nil {
return nil, fmt.Errorf("could not parse url %q: %v", daemon, err)
}
var c net.Conn
switch daemonUrl.Scheme {
case "unix":
c, err = net.DialTimeout(daemonUrl.Scheme, daemonUrl.Path, time.Duration(10*time.Second))
case "tcp":
c, err = net.DialTimeout(daemonUrl.Scheme, daemonUrl.Host, time.Duration(10*time.Second))
default:
err = fmt.Errorf("unknown scheme %v", daemonUrl.Scheme)
}
if err != nil {
return nil, fmt.Errorf("could not dial docker daemon at %s: %v", daemon, err)
return nil, fmt.Errorf("could not dial docker daemon: %v", err)
}
client := httputil.NewClientConn(c, nil)