mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #17008 from liaoqingwei/dev1
Update testcases: use of checkers on docker_cli_nat_test.go
This commit is contained in:
commit
bece5b82a8
1 changed files with 16 additions and 30 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
|
@ -17,9 +18,7 @@ func startServerContainer(c *check.C, msg string, port int) string {
|
|||
"busybox",
|
||||
"sh", "-c", fmt.Sprintf("echo %q | nc -lp %d", msg, port),
|
||||
}
|
||||
if err := waitForContainer(name, cmd...); err != nil {
|
||||
c.Fatalf("Failed to launch server container: %v", err)
|
||||
}
|
||||
c.Assert(waitForContainer(name, cmd...), check.IsNil)
|
||||
return name
|
||||
}
|
||||
|
||||
|
@ -30,14 +29,11 @@ func getExternalAddress(c *check.C) net.IP {
|
|||
}
|
||||
|
||||
ifaceAddrs, err := iface.Addrs()
|
||||
if err != nil || len(ifaceAddrs) == 0 {
|
||||
c.Fatalf("Error retrieving addresses for eth0: %v (%d addresses)", err, len(ifaceAddrs))
|
||||
}
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(ifaceAddrs, checker.Not(checker.HasLen), 0)
|
||||
|
||||
ifaceIP, _, err := net.ParseCIDR(ifaceAddrs[0].String())
|
||||
if err != nil {
|
||||
c.Fatalf("Error retrieving the up for eth0: %s", err)
|
||||
}
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
return ifaceIP
|
||||
}
|
||||
|
@ -60,18 +56,14 @@ func (s *DockerSuite) TestNetworkNat(c *check.C) {
|
|||
startServerContainer(c, msg, 8080)
|
||||
endpoint := getExternalAddress(c)
|
||||
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", endpoint.String(), 8080))
|
||||
if err != nil {
|
||||
c.Fatalf("Failed to connect to container (%v)", err)
|
||||
}
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
data, err := ioutil.ReadAll(conn)
|
||||
conn.Close()
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
final := strings.TrimRight(string(data), "\n")
|
||||
if final != msg {
|
||||
c.Fatalf("Expected message %q but received %q", msg, final)
|
||||
}
|
||||
c.Assert(final, checker.Equals, msg)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestNetworkLocalhostTCPNat(c *check.C) {
|
||||
|
@ -82,18 +74,14 @@ func (s *DockerSuite) TestNetworkLocalhostTCPNat(c *check.C) {
|
|||
)
|
||||
startServerContainer(c, msg, 8081)
|
||||
conn, err := net.Dial("tcp", "localhost:8081")
|
||||
if err != nil {
|
||||
c.Fatalf("Failed to connect to container (%v)", err)
|
||||
}
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
data, err := ioutil.ReadAll(conn)
|
||||
conn.Close()
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
final := strings.TrimRight(string(data), "\n")
|
||||
if final != msg {
|
||||
c.Fatalf("Expected message %q but received %q", msg, final)
|
||||
}
|
||||
c.Assert(final, checker.Equals, msg)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestNetworkLoopbackNat(c *check.C) {
|
||||
|
@ -105,7 +93,5 @@ func (s *DockerSuite) TestNetworkLoopbackNat(c *check.C) {
|
|||
out, _ := dockerCmd(c, "run", "-t", "--net=container:server", "busybox",
|
||||
"sh", "-c", fmt.Sprintf("stty raw && nc -w 5 %s 8080", endpoint.String()))
|
||||
final := strings.TrimRight(string(out), "\n")
|
||||
if final != msg {
|
||||
c.Fatalf("Expected message %q but received %q", msg, final)
|
||||
}
|
||||
c.Assert(final, checker.Equals, msg)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue