@@ -4,14 +4,15 @@ import (
44 "fmt"
55 "net"
66 "os/exec"
7- "strconv"
87 "strings"
98
109 "github.com/go-check/check"
1110)
1211
1312func startServerContainer (c * check.C , proto string , port int ) string {
14- cmd := []string {"-d" , "-p" , fmt .Sprintf ("%d:%d" , port , port ), "busybox" , "nc" , "-lp" , strconv .Itoa (port )}
13+ pStr := fmt .Sprintf ("%d:%d" , port , port )
14+ bCmd := fmt .Sprintf ("nc -lp %d && echo bye" , port )
15+ cmd := []string {"-d" , "-p" , pStr , "busybox" , "sh" , "-c" , bCmd }
1516 if proto == "udp" {
1617 cmd = append (cmd , "-u" )
1718 }
@@ -75,7 +76,13 @@ func (s *DockerSuite) TestNetworkNat(c *check.C) {
7576 }
7677
7778 result := getContainerLogs (c , srv )
78- if expected := "hello world" ; result != expected {
79+
80+ // Ideally we'd like to check for "hello world" but sometimes
81+ // nc doesn't show the data it received so instead let's look for
82+ // the output of the 'echo bye' that should be printed once
83+ // the nc command gets a connection
84+ expected := "bye"
85+ if ! strings .Contains (result , expected ) {
7986 c .Fatalf ("Unexpected output. Expected: %q, received: %q" , expected , result )
8087 }
8188}
@@ -97,7 +104,13 @@ func (s *DockerSuite) TestNetworkLocalhostTCPNat(c *check.C) {
97104 conn .Close ()
98105
99106 result := getContainerLogs (c , srv )
100- if expected := "hello world" ; result != expected {
107+
108+ // Ideally we'd like to check for "hello world" but sometimes
109+ // nc doesn't show the data it received so instead let's look for
110+ // the output of the 'echo bye' that should be printed once
111+ // the nc command gets a connection
112+ expected := "bye"
113+ if ! strings .Contains (result , expected ) {
101114 c .Fatalf ("Unexpected output. Expected: %q, received: %q" , expected , result )
102115 }
103116}
0 commit comments