Files
docker-cli/components/engine/integration-cli/docker_cli_proxy_test.go
Ahmet Alp Balkan de1d7d8288 integ-cli: also preserve SystemRoot env var
Windows CI fails to dial remote test host over tcp in the test cases where
we clear environment variables during `exec(dockerBinary, ...)` in the
absence of `SystemRoot` environment variable (typically points to `c:\windows`).

This fixes tests:
- `TestRunEnvironmentErase`
- `TestRunEnvironmentOverride`

Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
Upstream-commit: d18689dff71ccbc3b955a4416ae04077356fd5c9
Component: engine
2015-03-07 01:09:01 -08:00

63 lines
1.5 KiB
Go

package main
import (
"net"
"os/exec"
"strings"
"testing"
)
func TestCliProxyDisableProxyUnixSock(t *testing.T) {
cmd := exec.Command(dockerBinary, "info")
cmd.Env = appendBaseEnv([]string{"HTTP_PROXY=http://127.0.0.1:9999"})
if out, _, err := runCommandWithOutput(cmd); err != nil {
t.Fatal(err, out)
}
logDone("cli proxy - HTTP_PROXY is not used when connecting to unix sock")
}
// Can't use localhost here since go has a special case to not use proxy if connecting to localhost
// See http://golang.org/pkg/net/http/#ProxyFromEnvironment
func TestCliProxyProxyTCPSock(t *testing.T) {
testRequires(t, SameHostDaemon)
// get the IP to use to connect since we can't use localhost
addrs, err := net.InterfaceAddrs()
if err != nil {
t.Fatal(err)
}
var ip string
for _, addr := range addrs {
sAddr := addr.String()
if !strings.Contains(sAddr, "127.0.0.1") {
addrArr := strings.Split(sAddr, "/")
ip = addrArr[0]
break
}
}
if ip == "" {
t.Fatal("could not find ip to connect to")
}
d := NewDaemon(t)
if err := d.Start("-H", "tcp://"+ip+":2375"); err != nil {
t.Fatal(err)
}
cmd := exec.Command(dockerBinary, "info")
cmd.Env = []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"}
if out, _, err := runCommandWithOutput(cmd); err == nil {
t.Fatal(err, out)
}
// Test with no_proxy
cmd.Env = append(cmd.Env, "NO_PROXY="+ip)
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "info")); err != nil {
t.Fatal(err, out)
}
logDone("cli proxy - HTTP_PROXY is used for TCP sock")
}