Jelajahi Sumber

Merge pull request #16870 from cxxly/16756-refactor-docker_cli_proxy_test

refactor docker_cli_proxy_test.go
Vincent Demeester 9 tahun lalu
induk
melakukan
19ff8e09ba
1 mengubah file dengan 11 tambahan dan 21 penghapusan
  1. 11 21
      integration-cli/docker_cli_proxy_test.go

+ 11 - 21
integration-cli/docker_cli_proxy_test.go

@@ -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,16 @@ 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.Not(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))
 }