Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestGetContainersAttachWebsocket: use DOCKER_TEST_HOST if specified #10747

Merged
merged 1 commit into from Feb 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions integration-cli/docker_api_attach_test.go
Expand Up @@ -2,9 +2,9 @@ package main

import (
"bytes"
"net"
"os/exec"
"testing"
"time"

"code.google.com/p/go.net/websocket"
)
Expand All @@ -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)
}
Expand Down
32 changes: 18 additions & 14 deletions integration-cli/docker_utils.go
Expand Up @@ -273,16 +273,7 @@ func daemonHost() string {
return daemonUrlStr
}

func sockRequest(method, endpoint string, data interface{}) ([]byte, error) {
jsonData := bytes.NewBuffer(nil)
if err := json.NewEncoder(jsonData).Encode(data); err != nil {
return nil, err
}

return sockRequestRaw(method, endpoint, jsonData, "application/json")
}

func sockRequestRaw(method, endpoint string, data io.Reader, ct string) ([]byte, error) {
func sockConn(timeout time.Duration) (net.Conn, error) {
daemon := daemonHost()
daemonUrl, err := url.Parse(daemon)
if err != nil {
Expand All @@ -292,14 +283,27 @@ func sockRequestRaw(method, endpoint string, data io.Reader, ct string) ([]byte,
var c net.Conn
switch daemonUrl.Scheme {
case "unix":
c, err = net.DialTimeout(daemonUrl.Scheme, daemonUrl.Path, time.Duration(10*time.Second))
return net.DialTimeout(daemonUrl.Scheme, daemonUrl.Path, timeout)
case "tcp":
c, err = net.DialTimeout(daemonUrl.Scheme, daemonUrl.Host, time.Duration(10*time.Second))
return net.DialTimeout(daemonUrl.Scheme, daemonUrl.Host, timeout)
default:
err = fmt.Errorf("unknown scheme %v", daemonUrl.Scheme)
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 {
return nil, err
}

return sockRequestRaw(method, endpoint, jsonData, "application/json")
}

func sockRequestRaw(method, endpoint string, data io.Reader, ct string) ([]byte, error) {
c, err := sockConn(time.Duration(10 * time.Second))
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)
Expand Down