Skip to content

Commit 68c7d24

Browse files
author
John Howard
committed
Move TestPort out of _unix
Signed-off-by: John Howard <jhoward@microsoft.com>
1 parent 166412e commit 68c7d24

File tree

2 files changed

+47
-56
lines changed

2 files changed

+47
-56
lines changed

integration-cli/docker_cli_port_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"net"
56
"regexp"
67
"sort"
78
"strings"
@@ -245,3 +246,49 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
245246
c.Errorf("Missing unpublished ports or port binding (%s, %s) in docker ps output: %s", unpPort1, expBnd2, out)
246247
}
247248
}
249+
250+
func (s *DockerSuite) TestPortHostBinding(c *check.C) {
251+
out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox",
252+
"nc", "-l", "-p", "80")
253+
firstID := strings.TrimSpace(out)
254+
255+
out, _ = dockerCmd(c, "port", firstID, "80")
256+
257+
if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
258+
c.Error("Port list is not correct")
259+
}
260+
261+
dockerCmd(c, "run", "--net=host", "busybox",
262+
"nc", "localhost", "9876")
263+
264+
dockerCmd(c, "rm", "-f", firstID)
265+
266+
if _, _, err := dockerCmdWithError("run", "--net=host", "busybox",
267+
"nc", "localhost", "9876"); err == nil {
268+
c.Error("Port is still bound after the Container is removed")
269+
}
270+
}
271+
272+
func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
273+
out, _ := dockerCmd(c, "run", "-d", "-P", "--expose", "80", "busybox",
274+
"nc", "-l", "-p", "80")
275+
firstID := strings.TrimSpace(out)
276+
277+
out, _ = dockerCmd(c, "port", firstID, "80")
278+
279+
_, exposedPort, err := net.SplitHostPort(out)
280+
281+
if err != nil {
282+
c.Fatal(out, err)
283+
}
284+
285+
dockerCmd(c, "run", "--net=host", "busybox",
286+
"nc", "localhost", strings.TrimSpace(exposedPort))
287+
288+
dockerCmd(c, "rm", "-f", firstID)
289+
290+
if _, _, err = dockerCmdWithError("run", "--net=host", "busybox",
291+
"nc", "localhost", strings.TrimSpace(exposedPort)); err == nil {
292+
c.Error("Port is still bound after the Container is removed")
293+
}
294+
}

integration-cli/docker_cli_port_unix_test.go

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)