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
1 changed files with 11 additions and 22 deletions

View File

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