FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
docker/integration-cli/docker_cli_nat_test.go at master · Eagle-X/docker · GitHub
Eagle-X
/
docker
Public
forked from
moby/moby
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
docker
/
integration-cli
/
docker_cli_nat_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
111 lines (99 loc) · 2.91 KB
Breadcrumbs
docker
/
integration-cli
/
docker_cli_nat_test.go
Copy path
File metadata and controls
111 lines (99 loc) · 2.91 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package
main
import
(
"fmt"
"io/ioutil"
"net"
"strings"
"github.com/go-check/check"
)
func
startServerContainer
(
c
*
check.
C
,
msg
string
,
port
int
)
string
{
name
:=
"server"
cmd
:=
[]
string
{
"-d"
,
"-p"
,
fmt
.
Sprintf
(
"%d:%d"
,
port
,
port
),
"busybox"
,
"sh"
,
"-c"
,
fmt
.
Sprintf
(
"echo %q | nc -lp %d"
,
msg
,
port
),
}
if
err
:=
waitForContainer
(
name
,
cmd
...
);
err
!=
nil
{
c
.
Fatalf
(
"Failed to launch server container: %v"
,
err
)
}
return
name
}
func
getExternalAddress
(
c
*
check.
C
) net.
IP
{
iface
,
err
:=
net
.
InterfaceByName
(
"eth0"
)
if
err
!=
nil
{
c
.
Skip
(
fmt
.
Sprintf
(
"Test not running with `make test`. Interface eth0 not found: %v"
,
err
))
}
ifaceAddrs
,
err
:=
iface
.
Addrs
()
if
err
!=
nil
||
len
(
ifaceAddrs
)
==
0
{
c
.
Fatalf
(
"Error retrieving addresses for eth0: %v (%d addresses)"
,
err
,
len
(
ifaceAddrs
))
}
ifaceIP
,
_
,
err
:=
net
.
ParseCIDR
(
ifaceAddrs
[
0
].
String
())
if
err
!=
nil
{
c
.
Fatalf
(
"Error retrieving the up for eth0: %s"
,
err
)
}
return
ifaceIP
}
func
getContainerLogs
(
c
*
check.
C
,
containerID
string
)
string
{
out
,
_
:=
dockerCmd
(
c
,
"logs"
,
containerID
)
return
strings
.
Trim
(
out
,
"
\r
\n
"
)
}
func
getContainerStatus
(
c
*
check.
C
,
containerID
string
)
string
{
out
,
err
:=
inspectField
(
containerID
,
"State.Running"
)
c
.
Assert
(
err
,
check
.
IsNil
)
return
out
}
func
(
s
*
DockerSuite
)
TestNetworkNat
(
c
*
check.
C
) {
testRequires
(
c
,
DaemonIsLinux
)
testRequires
(
c
,
SameHostDaemon
,
NativeExecDriver
)
msg
:=
"it works"
startServerContainer
(
c
,
msg
,
8080
)
endpoint
:=
getExternalAddress
(
c
)
conn
,
err
:=
net
.
Dial
(
"tcp"
,
fmt
.
Sprintf
(
"%s:%d"
,
endpoint
.
String
(),
8080
))
if
err
!=
nil
{
c
.
Fatalf
(
"Failed to connect to container (%v)"
,
err
)
}
data
,
err
:=
ioutil
.
ReadAll
(
conn
)
conn
.
Close
()
if
err
!=
nil
{
c
.
Fatal
(
err
)
}
final
:=
strings
.
TrimRight
(
string
(
data
),
"
\n
"
)
if
final
!=
msg
{
c
.
Fatalf
(
"Expected message %q but received %q"
,
msg
,
final
)
}
}
func
(
s
*
DockerSuite
)
TestNetworkLocalhostTCPNat
(
c
*
check.
C
) {
testRequires
(
c
,
DaemonIsLinux
)
testRequires
(
c
,
SameHostDaemon
,
NativeExecDriver
)
var
(
msg
=
"hi yall"
)
startServerContainer
(
c
,
msg
,
8081
)
conn
,
err
:=
net
.
Dial
(
"tcp"
,
"localhost:8081"
)
if
err
!=
nil
{
c
.
Fatalf
(
"Failed to connect to container (%v)"
,
err
)
}
data
,
err
:=
ioutil
.
ReadAll
(
conn
)
conn
.
Close
()
if
err
!=
nil
{
c
.
Fatal
(
err
)
}
final
:=
strings
.
TrimRight
(
string
(
data
),
"
\n
"
)
if
final
!=
msg
{
c
.
Fatalf
(
"Expected message %q but received %q"
,
msg
,
final
)
}
}
func
(
s
*
DockerSuite
)
TestNetworkLoopbackNat
(
c
*
check.
C
) {
testRequires
(
c
,
DaemonIsLinux
)
testRequires
(
c
,
SameHostDaemon
,
NativeExecDriver
,
NotUserNamespace
)
msg
:=
"it works"
startServerContainer
(
c
,
msg
,
8080
)
endpoint
:=
getExternalAddress
(
c
)
out
,
_
:=
dockerCmd
(
c
,
"run"
,
"-t"
,
"--net=container:server"
,
"busybox"
,
"sh"
,
"-c"
,
fmt
.
Sprintf
(
"stty raw && nc -w 5 %s 8080"
,
endpoint
.
String
()))
final
:=
strings
.
TrimRight
(
string
(
out
),
"
\n
"
)
if
final
!=
msg
{
c
.
Fatalf
(
"Expected message %q but received %q"
,
msg
,
final
)
}
}
Back
|
FazBrowse Home
|
New Git URL