Take DOCKER_TEST_HOST into account
Tests no longer make the assumption that the daemon can be accessed through unix:///var/run/docker.sock. Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
This commit is contained in:
parent
95c0f07966
commit
e1ef33449f
1 changed files with 25 additions and 4 deletions
|
@ -11,6 +11,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
@ -264,12 +265,32 @@ func (d *Daemon) Cmd(name string, arg ...string) (string, error) {
|
||||||
return string(b), err
|
return string(b), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func daemonHost() string {
|
||||||
|
daemonUrlStr := "unix:///var/run/docker.sock"
|
||||||
|
if daemonHostVar := os.Getenv("DOCKER_TEST_HOST"); daemonHostVar != "" {
|
||||||
|
daemonUrlStr = daemonHostVar
|
||||||
|
}
|
||||||
|
return daemonUrlStr
|
||||||
|
}
|
||||||
|
|
||||||
func sockRequest(method, endpoint string, data interface{}) ([]byte, error) {
|
func sockRequest(method, endpoint string, data interface{}) ([]byte, error) {
|
||||||
// FIX: the path to sock should not be hardcoded
|
daemon := daemonHost()
|
||||||
sock := filepath.Join("/", "var", "run", "docker.sock")
|
daemonUrl, err := url.Parse(daemon)
|
||||||
c, err := net.DialTimeout("unix", sock, time.Duration(10*time.Second))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not dial docker sock at %s: %v", sock, err)
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
client := httputil.NewClientConn(c, nil)
|
client := httputil.NewClientConn(c, nil)
|
||||||
|
|
Loading…
Reference in a new issue