mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Move TestPort out of _unix
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
parent
166412e529
commit
68c7d24a12
2 changed files with 47 additions and 56 deletions
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
@ -245,3 +246,49 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
|
|||
c.Errorf("Missing unpublished ports or port binding (%s, %s) in docker ps output: %s", unpPort1, expBnd2, out)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPortHostBinding(c *check.C) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox",
|
||||
"nc", "-l", "-p", "80")
|
||||
firstID := strings.TrimSpace(out)
|
||||
|
||||
out, _ = dockerCmd(c, "port", firstID, "80")
|
||||
|
||||
if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
|
||||
c.Error("Port list is not correct")
|
||||
}
|
||||
|
||||
dockerCmd(c, "run", "--net=host", "busybox",
|
||||
"nc", "localhost", "9876")
|
||||
|
||||
dockerCmd(c, "rm", "-f", firstID)
|
||||
|
||||
if _, _, err := dockerCmdWithError("run", "--net=host", "busybox",
|
||||
"nc", "localhost", "9876"); err == nil {
|
||||
c.Error("Port is still bound after the Container is removed")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "-P", "--expose", "80", "busybox",
|
||||
"nc", "-l", "-p", "80")
|
||||
firstID := strings.TrimSpace(out)
|
||||
|
||||
out, _ = dockerCmd(c, "port", firstID, "80")
|
||||
|
||||
_, exposedPort, err := net.SplitHostPort(out)
|
||||
|
||||
if err != nil {
|
||||
c.Fatal(out, err)
|
||||
}
|
||||
|
||||
dockerCmd(c, "run", "--net=host", "busybox",
|
||||
"nc", "localhost", strings.TrimSpace(exposedPort))
|
||||
|
||||
dockerCmd(c, "rm", "-f", firstID)
|
||||
|
||||
if _, _, err = dockerCmdWithError("run", "--net=host", "busybox",
|
||||
"nc", "localhost", strings.TrimSpace(exposedPort)); err == nil {
|
||||
c.Error("Port is still bound after the Container is removed")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
// +build !windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestPortHostBinding(c *check.C) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox",
|
||||
"nc", "-l", "-p", "80")
|
||||
firstID := strings.TrimSpace(out)
|
||||
|
||||
out, _ = dockerCmd(c, "port", firstID, "80")
|
||||
|
||||
if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
|
||||
c.Error("Port list is not correct")
|
||||
}
|
||||
|
||||
dockerCmd(c, "run", "--net=host", "busybox",
|
||||
"nc", "localhost", "9876")
|
||||
|
||||
dockerCmd(c, "rm", "-f", firstID)
|
||||
|
||||
if _, _, err := dockerCmdWithError("run", "--net=host", "busybox",
|
||||
"nc", "localhost", "9876"); err == nil {
|
||||
c.Error("Port is still bound after the Container is removed")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "-P", "--expose", "80", "busybox",
|
||||
"nc", "-l", "-p", "80")
|
||||
firstID := strings.TrimSpace(out)
|
||||
|
||||
out, _ = dockerCmd(c, "port", firstID, "80")
|
||||
|
||||
_, exposedPort, err := net.SplitHostPort(out)
|
||||
|
||||
if err != nil {
|
||||
c.Fatal(out, err)
|
||||
}
|
||||
|
||||
dockerCmd(c, "run", "--net=host", "busybox",
|
||||
"nc", "localhost", strings.TrimSpace(exposedPort))
|
||||
|
||||
dockerCmd(c, "rm", "-f", firstID)
|
||||
|
||||
if _, _, err = dockerCmdWithError("run", "--net=host", "busybox",
|
||||
"nc", "localhost", strings.TrimSpace(exposedPort)); err == nil {
|
||||
c.Error("Port is still bound after the Container is removed")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue