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"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/integration/checker"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -17,9 +18,7 @@ func startServerContainer(c *check.C, msg string, port int) string {
|
||||||
"busybox",
|
"busybox",
|
||||||
"sh", "-c", fmt.Sprintf("echo %q | nc -lp %d", msg, port),
|
"sh", "-c", fmt.Sprintf("echo %q | nc -lp %d", msg, port),
|
||||||
}
|
}
|
||||||
if err := waitForContainer(name, cmd...); err != nil {
|
c.Assert(waitForContainer(name, cmd...), check.IsNil)
|
||||||
c.Fatalf("Failed to launch server container: %v", err)
|
|
||||||
}
|
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,14 +29,11 @@ func getExternalAddress(c *check.C) net.IP {
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaceAddrs, err := iface.Addrs()
|
ifaceAddrs, err := iface.Addrs()
|
||||||
if err != nil || len(ifaceAddrs) == 0 {
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatalf("Error retrieving addresses for eth0: %v (%d addresses)", err, len(ifaceAddrs))
|
c.Assert(ifaceAddrs, checker.Not(checker.HasLen), 0)
|
||||||
}
|
|
||||||
|
|
||||||
ifaceIP, _, err := net.ParseCIDR(ifaceAddrs[0].String())
|
ifaceIP, _, err := net.ParseCIDR(ifaceAddrs[0].String())
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatalf("Error retrieving the up for eth0: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ifaceIP
|
return ifaceIP
|
||||||
}
|
}
|
||||||
|
@ -60,18 +56,14 @@ func (s *DockerSuite) TestNetworkNat(c *check.C) {
|
||||||
startServerContainer(c, msg, 8080)
|
startServerContainer(c, msg, 8080)
|
||||||
endpoint := getExternalAddress(c)
|
endpoint := getExternalAddress(c)
|
||||||
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", endpoint.String(), 8080))
|
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", endpoint.String(), 8080))
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatalf("Failed to connect to container (%v)", err)
|
|
||||||
}
|
|
||||||
data, err := ioutil.ReadAll(conn)
|
data, err := ioutil.ReadAll(conn)
|
||||||
conn.Close()
|
conn.Close()
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatal(err)
|
|
||||||
}
|
|
||||||
final := strings.TrimRight(string(data), "\n")
|
final := strings.TrimRight(string(data), "\n")
|
||||||
if final != msg {
|
c.Assert(final, checker.Equals, msg)
|
||||||
c.Fatalf("Expected message %q but received %q", msg, final)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestNetworkLocalhostTCPNat(c *check.C) {
|
func (s *DockerSuite) TestNetworkLocalhostTCPNat(c *check.C) {
|
||||||
|
@ -82,18 +74,14 @@ func (s *DockerSuite) TestNetworkLocalhostTCPNat(c *check.C) {
|
||||||
)
|
)
|
||||||
startServerContainer(c, msg, 8081)
|
startServerContainer(c, msg, 8081)
|
||||||
conn, err := net.Dial("tcp", "localhost:8081")
|
conn, err := net.Dial("tcp", "localhost:8081")
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatalf("Failed to connect to container (%v)", err)
|
|
||||||
}
|
|
||||||
data, err := ioutil.ReadAll(conn)
|
data, err := ioutil.ReadAll(conn)
|
||||||
conn.Close()
|
conn.Close()
|
||||||
if err != nil {
|
c.Assert(err, check.IsNil)
|
||||||
c.Fatal(err)
|
|
||||||
}
|
|
||||||
final := strings.TrimRight(string(data), "\n")
|
final := strings.TrimRight(string(data), "\n")
|
||||||
if final != msg {
|
c.Assert(final, checker.Equals, msg)
|
||||||
c.Fatalf("Expected message %q but received %q", msg, final)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestNetworkLoopbackNat(c *check.C) {
|
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",
|
out, _ := dockerCmd(c, "run", "-t", "--net=container:server", "busybox",
|
||||||
"sh", "-c", fmt.Sprintf("stty raw && nc -w 5 %s 8080", endpoint.String()))
|
"sh", "-c", fmt.Sprintf("stty raw && nc -w 5 %s 8080", endpoint.String()))
|
||||||
final := strings.TrimRight(string(out), "\n")
|
final := strings.TrimRight(string(out), "\n")
|
||||||
if final != msg {
|
c.Assert(final, checker.Equals, msg)
|
||||||
c.Fatalf("Expected message %q but received %q", msg, final)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue