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>
| ... | ... |
@@ -2,9 +2,9 @@ package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 |
- "net" |
|
| 6 | 5 |
"os/exec" |
| 7 | 6 |
"testing" |
| 7 |
+ "time" |
|
| 8 | 8 |
|
| 9 | 9 |
"code.google.com/p/go.net/websocket" |
| 10 | 10 |
) |
| ... | ... |
@@ -17,7 +17,7 @@ func TestGetContainersAttachWebsocket(t *testing.T) {
|
| 17 | 17 |
} |
| 18 | 18 |
defer deleteAllContainers() |
| 19 | 19 |
|
| 20 |
- rwc, err := net.Dial("unix", "/var/run/docker.sock")
|
|
| 20 |
+ rwc, err := sockConn(time.Duration(10 * time.Second)) |
|
| 21 | 21 |
if err != nil {
|
| 22 | 22 |
t.Fatal(err) |
| 23 | 23 |
} |
| ... | ... |
@@ -273,16 +273,7 @@ func daemonHost() string {
|
| 273 | 273 |
return daemonUrlStr |
| 274 | 274 |
} |
| 275 | 275 |
|
| 276 |
-func sockRequest(method, endpoint string, data interface{}) ([]byte, error) {
|
|
| 277 |
- jsonData := bytes.NewBuffer(nil) |
|
| 278 |
- if err := json.NewEncoder(jsonData).Encode(data); err != nil {
|
|
| 279 |
- return nil, err |
|
| 280 |
- } |
|
| 281 |
- |
|
| 282 |
- return sockRequestRaw(method, endpoint, jsonData, "application/json") |
|
| 283 |
-} |
|
| 284 |
- |
|
| 285 |
-func sockRequestRaw(method, endpoint string, data io.Reader, ct string) ([]byte, error) {
|
|
| 276 |
+func sockConn(timeout time.Duration) (net.Conn, error) {
|
|
| 286 | 277 |
daemon := daemonHost() |
| 287 | 278 |
daemonUrl, err := url.Parse(daemon) |
| 288 | 279 |
if err != nil {
|
| ... | ... |
@@ -292,14 +283,27 @@ func sockRequestRaw(method, endpoint string, data io.Reader, ct string) ([]byte, |
| 292 | 292 |
var c net.Conn |
| 293 | 293 |
switch daemonUrl.Scheme {
|
| 294 | 294 |
case "unix": |
| 295 |
- c, err = net.DialTimeout(daemonUrl.Scheme, daemonUrl.Path, time.Duration(10*time.Second)) |
|
| 295 |
+ return net.DialTimeout(daemonUrl.Scheme, daemonUrl.Path, timeout) |
|
| 296 | 296 |
case "tcp": |
| 297 |
- c, err = net.DialTimeout(daemonUrl.Scheme, daemonUrl.Host, time.Duration(10*time.Second)) |
|
| 297 |
+ return net.DialTimeout(daemonUrl.Scheme, daemonUrl.Host, timeout) |
|
| 298 | 298 |
default: |
| 299 |
- err = fmt.Errorf("unknown scheme %v", daemonUrl.Scheme)
|
|
| 299 |
+ return c, fmt.Errorf("unknown scheme %v (%s)", daemonUrl.Scheme, daemon)
|
|
| 300 |
+ } |
|
| 301 |
+} |
|
| 302 |
+ |
|
| 303 |
+func sockRequest(method, endpoint string, data interface{}) ([]byte, error) {
|
|
| 304 |
+ jsonData := bytes.NewBuffer(nil) |
|
| 305 |
+ if err := json.NewEncoder(jsonData).Encode(data); err != nil {
|
|
| 306 |
+ return nil, err |
|
| 300 | 307 |
} |
| 308 |
+ |
|
| 309 |
+ return sockRequestRaw(method, endpoint, jsonData, "application/json") |
|
| 310 |
+} |
|
| 311 |
+ |
|
| 312 |
+func sockRequestRaw(method, endpoint string, data io.Reader, ct string) ([]byte, error) {
|
|
| 313 |
+ c, err := sockConn(time.Duration(10 * time.Second)) |
|
| 301 | 314 |
if err != nil {
|
| 302 |
- return nil, fmt.Errorf("could not dial docker daemon at %s: %v", daemon, err)
|
|
| 315 |
+ return nil, fmt.Errorf("could not dial docker daemon: %v", err)
|
|
| 303 | 316 |
} |
| 304 | 317 |
|
| 305 | 318 |
client := httputil.NewClientConn(c, nil) |