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

refactor docker_cli_proxy_test.go

part of #16756

Signed-off-by: Xiaoxu Chen <chenxiaoxu14@otcaix.iscas.ac.cn>
This commit is contained in:
Xiaoxu Chen 2015-10-09 11:11:05 +08:00
parent 6654b0e05f
commit 14f43406a3

View file

@ -5,6 +5,7 @@ import (
"os/exec" "os/exec"
"strings" "strings"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check" "github.com/go-check/check"
) )
@ -15,9 +16,8 @@ func (s *DockerSuite) TestCliProxyDisableProxyUnixSock(c *check.C) {
cmd := exec.Command(dockerBinary, "info") cmd := exec.Command(dockerBinary, "info")
cmd.Env = appendBaseEnv([]string{"HTTP_PROXY=http://127.0.0.1:9999"}) cmd.Env = appendBaseEnv([]string{"HTTP_PROXY=http://127.0.0.1:9999"})
if out, _, err := runCommandWithOutput(cmd); err != nil { out, _, err := runCommandWithOutput(cmd)
c.Fatal(err, out) c.Assert(err, checker.IsNil, check.Commentf("%v", out))
}
} }
@ -27,9 +27,7 @@ func (s *DockerDaemonSuite) TestCliProxyProxyTCPSock(c *check.C) {
testRequires(c, SameHostDaemon) testRequires(c, SameHostDaemon)
// get the IP to use to connect since we can't use localhost // get the IP to use to connect since we can't use localhost
addrs, err := net.InterfaceAddrs() addrs, err := net.InterfaceAddrs()
if err != nil { c.Assert(err, checker.IsNil)
c.Fatal(err)
}
var ip string var ip string
for _, addr := range addrs { for _, addr := range addrs {
sAddr := addr.String() sAddr := addr.String()
@ -40,24 +38,15 @@ func (s *DockerDaemonSuite) TestCliProxyProxyTCPSock(c *check.C) {
} }
} }
if ip == "" { c.Assert(ip, checker.Equals, "")
c.Fatal("could not find ip to connect to") err = s.d.Start("-H", "tcp://"+ip+":2375")
} c.Assert(err, checker.IsNil)
if err := s.d.Start("-H", "tcp://"+ip+":2375"); err != nil {
c.Fatal(err)
}
cmd := exec.Command(dockerBinary, "info") cmd := exec.Command(dockerBinary, "info")
cmd.Env = []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"} cmd.Env = []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"}
if out, _, err := runCommandWithOutput(cmd); err == nil { out, _, err := runCommandWithOutput(cmd)
c.Fatal(err, out) c.Assert(err, checker.NotNil, check.Commentf("%v", out))
}
// Test with no_proxy // Test with no_proxy
cmd.Env = append(cmd.Env, "NO_PROXY="+ip) cmd.Env = append(cmd.Env, "NO_PROXY="+ip)
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "info")); err != nil { out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "info"))
c.Fatal(err, out) c.Assert(err, checker.IsNil, check.Commentf("%v", out))
}
} }