Browse code

Move TestPort out of _unix

Signed-off-by: John Howard <jhoward@microsoft.com>

John Howard authored on 2015/09/01 06:40:36
Showing 2 changed files
... ...
@@ -2,6 +2,7 @@ package main
2 2
 
3 3
 import (
4 4
 	"fmt"
5
+	"net"
5 6
 	"regexp"
6 7
 	"sort"
7 8
 	"strings"
... ...
@@ -245,3 +246,49 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
245 245
 		c.Errorf("Missing unpublished ports or port binding (%s, %s) in docker ps output: %s", unpPort1, expBnd2, out)
246 246
 	}
247 247
 }
248
+
249
+func (s *DockerSuite) TestPortHostBinding(c *check.C) {
250
+	out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox",
251
+		"nc", "-l", "-p", "80")
252
+	firstID := strings.TrimSpace(out)
253
+
254
+	out, _ = dockerCmd(c, "port", firstID, "80")
255
+
256
+	if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
257
+		c.Error("Port list is not correct")
258
+	}
259
+
260
+	dockerCmd(c, "run", "--net=host", "busybox",
261
+		"nc", "localhost", "9876")
262
+
263
+	dockerCmd(c, "rm", "-f", firstID)
264
+
265
+	if _, _, err := dockerCmdWithError("run", "--net=host", "busybox",
266
+		"nc", "localhost", "9876"); err == nil {
267
+		c.Error("Port is still bound after the Container is removed")
268
+	}
269
+}
270
+
271
+func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
272
+	out, _ := dockerCmd(c, "run", "-d", "-P", "--expose", "80", "busybox",
273
+		"nc", "-l", "-p", "80")
274
+	firstID := strings.TrimSpace(out)
275
+
276
+	out, _ = dockerCmd(c, "port", firstID, "80")
277
+
278
+	_, exposedPort, err := net.SplitHostPort(out)
279
+
280
+	if err != nil {
281
+		c.Fatal(out, err)
282
+	}
283
+
284
+	dockerCmd(c, "run", "--net=host", "busybox",
285
+		"nc", "localhost", strings.TrimSpace(exposedPort))
286
+
287
+	dockerCmd(c, "rm", "-f", firstID)
288
+
289
+	if _, _, err = dockerCmdWithError("run", "--net=host", "busybox",
290
+		"nc", "localhost", strings.TrimSpace(exposedPort)); err == nil {
291
+		c.Error("Port is still bound after the Container is removed")
292
+	}
293
+}
248 294
deleted file mode 100644
... ...
@@ -1,56 +0,0 @@
1
-// +build !windows
2
-
3
-package main
4
-
5
-import (
6
-	"net"
7
-	"strings"
8
-
9
-	"github.com/go-check/check"
10
-)
11
-
12
-func (s *DockerSuite) TestPortHostBinding(c *check.C) {
13
-	out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox",
14
-		"nc", "-l", "-p", "80")
15
-	firstID := strings.TrimSpace(out)
16
-
17
-	out, _ = dockerCmd(c, "port", firstID, "80")
18
-
19
-	if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
20
-		c.Error("Port list is not correct")
21
-	}
22
-
23
-	dockerCmd(c, "run", "--net=host", "busybox",
24
-		"nc", "localhost", "9876")
25
-
26
-	dockerCmd(c, "rm", "-f", firstID)
27
-
28
-	if _, _, err := dockerCmdWithError("run", "--net=host", "busybox",
29
-		"nc", "localhost", "9876"); err == nil {
30
-		c.Error("Port is still bound after the Container is removed")
31
-	}
32
-}
33
-
34
-func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
35
-	out, _ := dockerCmd(c, "run", "-d", "-P", "--expose", "80", "busybox",
36
-		"nc", "-l", "-p", "80")
37
-	firstID := strings.TrimSpace(out)
38
-
39
-	out, _ = dockerCmd(c, "port", firstID, "80")
40
-
41
-	_, exposedPort, err := net.SplitHostPort(out)
42
-
43
-	if err != nil {
44
-		c.Fatal(out, err)
45
-	}
46
-
47
-	dockerCmd(c, "run", "--net=host", "busybox",
48
-		"nc", "localhost", strings.TrimSpace(exposedPort))
49
-
50
-	dockerCmd(c, "rm", "-f", firstID)
51
-
52
-	if _, _, err = dockerCmdWithError("run", "--net=host", "busybox",
53
-		"nc", "localhost", strings.TrimSpace(exposedPort)); err == nil {
54
-		c.Error("Port is still bound after the Container is removed")
55
-	}
56
-}