Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
5923fd35
Commit
5923fd35
authored
Apr 30, 2016
by
zhouhaibing089
Committed by
haibzhou
May 05, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
followup to add http server close method
parent
43b644ea
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
33 deletions
+67
-33
genericapiserver_test.go
pkg/genericapiserver/genericapiserver_test.go
+1
-1
server_test.go
pkg/kubelet/server/server_test.go
+26
-1
http_test.go
pkg/probe/http/http_test.go
+31
-29
proxier_test.go
pkg/proxy/userspace/proxier_test.go
+9
-2
No files found.
pkg/genericapiserver/genericapiserver_test.go
View file @
5923fd35
...
@@ -141,8 +141,8 @@ func TestInstallAPIGroups(t *testing.T) {
...
@@ -141,8 +141,8 @@ func TestInstallAPIGroups(t *testing.T) {
}
}
s
.
InstallAPIGroups
(
apiGroupsInfo
)
s
.
InstallAPIGroups
(
apiGroupsInfo
)
// TODO: Close() this server when fix #19254
server
:=
httptest
.
NewServer
(
s
.
HandlerContainer
.
ServeMux
)
server
:=
httptest
.
NewServer
(
s
.
HandlerContainer
.
ServeMux
)
defer
server
.
Close
()
validPaths
:=
[]
string
{
validPaths
:=
[]
string
{
// "/api"
// "/api"
config
.
APIPrefix
,
config
.
APIPrefix
,
...
...
pkg/kubelet/server/server_test.go
View file @
5923fd35
...
@@ -214,7 +214,6 @@ func newServerTest() *serverTestFramework {
...
@@ -214,7 +214,6 @@ func newServerTest() *serverTestFramework {
true
,
true
,
&
kubecontainertesting
.
Mock
{})
&
kubecontainertesting
.
Mock
{})
fw
.
serverUnderTest
=
&
server
fw
.
serverUnderTest
=
&
server
// TODO: Close() this when fix #19254
fw
.
testHTTPServer
=
httptest
.
NewServer
(
fw
.
serverUnderTest
)
fw
.
testHTTPServer
=
httptest
.
NewServer
(
fw
.
serverUnderTest
)
return
fw
return
fw
}
}
...
@@ -244,6 +243,7 @@ func getPodName(name, namespace string) string {
...
@@ -244,6 +243,7 @@ func getPodName(name, namespace string) string {
func
TestContainerInfo
(
t
*
testing
.
T
)
{
func
TestContainerInfo
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
expectedInfo
:=
&
cadvisorapi
.
ContainerInfo
{}
expectedInfo
:=
&
cadvisorapi
.
ContainerInfo
{}
podID
:=
"somepod"
podID
:=
"somepod"
expectedPodID
:=
getPodName
(
podID
,
""
)
expectedPodID
:=
getPodName
(
podID
,
""
)
...
@@ -272,6 +272,7 @@ func TestContainerInfo(t *testing.T) {
...
@@ -272,6 +272,7 @@ func TestContainerInfo(t *testing.T) {
func
TestContainerInfoWithUidNamespace
(
t
*
testing
.
T
)
{
func
TestContainerInfoWithUidNamespace
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
expectedInfo
:=
&
cadvisorapi
.
ContainerInfo
{}
expectedInfo
:=
&
cadvisorapi
.
ContainerInfo
{}
podID
:=
"somepod"
podID
:=
"somepod"
expectedNamespace
:=
"custom"
expectedNamespace
:=
"custom"
...
@@ -302,6 +303,7 @@ func TestContainerInfoWithUidNamespace(t *testing.T) {
...
@@ -302,6 +303,7 @@ func TestContainerInfoWithUidNamespace(t *testing.T) {
func
TestContainerNotFound
(
t
*
testing
.
T
)
{
func
TestContainerNotFound
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
podID
:=
"somepod"
podID
:=
"somepod"
expectedNamespace
:=
"custom"
expectedNamespace
:=
"custom"
expectedContainerName
:=
"slowstartcontainer"
expectedContainerName
:=
"slowstartcontainer"
...
@@ -321,6 +323,7 @@ func TestContainerNotFound(t *testing.T) {
...
@@ -321,6 +323,7 @@ func TestContainerNotFound(t *testing.T) {
func
TestRootInfo
(
t
*
testing
.
T
)
{
func
TestRootInfo
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
expectedInfo
:=
&
cadvisorapi
.
ContainerInfo
{
expectedInfo
:=
&
cadvisorapi
.
ContainerInfo
{
ContainerReference
:
cadvisorapi
.
ContainerReference
{
ContainerReference
:
cadvisorapi
.
ContainerReference
{
Name
:
"/"
,
Name
:
"/"
,
...
@@ -349,6 +352,7 @@ func TestRootInfo(t *testing.T) {
...
@@ -349,6 +352,7 @@ func TestRootInfo(t *testing.T) {
func
TestSubcontainerContainerInfo
(
t
*
testing
.
T
)
{
func
TestSubcontainerContainerInfo
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
const
kubeletContainer
=
"/kubelet"
const
kubeletContainer
=
"/kubelet"
const
kubeletSubContainer
=
"/kubelet/sub"
const
kubeletSubContainer
=
"/kubelet/sub"
expectedInfo
:=
map
[
string
]
*
cadvisorapi
.
ContainerInfo
{
expectedInfo
:=
map
[
string
]
*
cadvisorapi
.
ContainerInfo
{
...
@@ -394,6 +398,7 @@ func TestSubcontainerContainerInfo(t *testing.T) {
...
@@ -394,6 +398,7 @@ func TestSubcontainerContainerInfo(t *testing.T) {
func
TestMachineInfo
(
t
*
testing
.
T
)
{
func
TestMachineInfo
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
expectedInfo
:=
&
cadvisorapi
.
MachineInfo
{
expectedInfo
:=
&
cadvisorapi
.
MachineInfo
{
NumCores
:
4
,
NumCores
:
4
,
MemoryCapacity
:
1024
,
MemoryCapacity
:
1024
,
...
@@ -419,6 +424,7 @@ func TestMachineInfo(t *testing.T) {
...
@@ -419,6 +424,7 @@ func TestMachineInfo(t *testing.T) {
func
TestServeLogs
(
t
*
testing
.
T
)
{
func
TestServeLogs
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
content
:=
string
(
`<pre><a href="kubelet.log">kubelet.log</a><a href="google.log">google.log</a></pre>`
)
content
:=
string
(
`<pre><a href="kubelet.log">kubelet.log</a><a href="google.log">google.log</a></pre>`
)
...
@@ -447,6 +453,7 @@ func TestServeLogs(t *testing.T) {
...
@@ -447,6 +453,7 @@ func TestServeLogs(t *testing.T) {
func
TestServeRunInContainer
(
t
*
testing
.
T
)
{
func
TestServeRunInContainer
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
output
:=
"foo bar"
output
:=
"foo bar"
podNamespace
:=
"other"
podNamespace
:=
"other"
podName
:=
"foo"
podName
:=
"foo"
...
@@ -487,6 +494,7 @@ func TestServeRunInContainer(t *testing.T) {
...
@@ -487,6 +494,7 @@ func TestServeRunInContainer(t *testing.T) {
func
TestServeRunInContainerWithUID
(
t
*
testing
.
T
)
{
func
TestServeRunInContainerWithUID
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
output
:=
"foo bar"
output
:=
"foo bar"
podNamespace
:=
"other"
podNamespace
:=
"other"
podName
:=
"foo"
podName
:=
"foo"
...
@@ -531,6 +539,7 @@ func TestServeRunInContainerWithUID(t *testing.T) {
...
@@ -531,6 +539,7 @@ func TestServeRunInContainerWithUID(t *testing.T) {
func
TestHealthCheck
(
t
*
testing
.
T
)
{
func
TestHealthCheck
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
fw
.
fakeKubelet
.
hostnameFunc
=
func
()
string
{
fw
.
fakeKubelet
.
hostnameFunc
=
func
()
string
{
return
"127.0.0.1"
return
"127.0.0.1"
}
}
...
@@ -563,6 +572,7 @@ type authTestCase struct {
...
@@ -563,6 +572,7 @@ type authTestCase struct {
func
TestAuthFilters
(
t
*
testing
.
T
)
{
func
TestAuthFilters
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
testcases
:=
[]
authTestCase
{}
testcases
:=
[]
authTestCase
{}
...
@@ -665,6 +675,7 @@ func TestAuthenticationFailure(t *testing.T) {
...
@@ -665,6 +675,7 @@ func TestAuthenticationFailure(t *testing.T) {
)
)
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
fw
.
fakeAuth
.
authenticateFunc
=
func
(
req
*
http
.
Request
)
(
user
.
Info
,
bool
,
error
)
{
fw
.
fakeAuth
.
authenticateFunc
=
func
(
req
*
http
.
Request
)
(
user
.
Info
,
bool
,
error
)
{
calledAuthenticate
=
true
calledAuthenticate
=
true
return
nil
,
false
,
nil
return
nil
,
false
,
nil
...
@@ -702,6 +713,7 @@ func TestAuthorizationSuccess(t *testing.T) {
...
@@ -702,6 +713,7 @@ func TestAuthorizationSuccess(t *testing.T) {
)
)
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
fw
.
fakeAuth
.
authenticateFunc
=
func
(
req
*
http
.
Request
)
(
user
.
Info
,
bool
,
error
)
{
fw
.
fakeAuth
.
authenticateFunc
=
func
(
req
*
http
.
Request
)
(
user
.
Info
,
bool
,
error
)
{
calledAuthenticate
=
true
calledAuthenticate
=
true
return
expectedUser
,
true
,
nil
return
expectedUser
,
true
,
nil
...
@@ -730,6 +742,7 @@ func TestAuthorizationSuccess(t *testing.T) {
...
@@ -730,6 +742,7 @@ func TestAuthorizationSuccess(t *testing.T) {
func
TestSyncLoopCheck
(
t
*
testing
.
T
)
{
func
TestSyncLoopCheck
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
fw
.
fakeKubelet
.
hostnameFunc
=
func
()
string
{
fw
.
fakeKubelet
.
hostnameFunc
=
func
()
string
{
return
"127.0.0.1"
return
"127.0.0.1"
}
}
...
@@ -746,6 +759,7 @@ func TestSyncLoopCheck(t *testing.T) {
...
@@ -746,6 +759,7 @@ func TestSyncLoopCheck(t *testing.T) {
func
TestPLEGHealthCheck
(
t
*
testing
.
T
)
{
func
TestPLEGHealthCheck
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
fw
.
fakeKubelet
.
hostnameFunc
=
func
()
string
{
fw
.
fakeKubelet
.
hostnameFunc
=
func
()
string
{
return
"127.0.0.1"
return
"127.0.0.1"
}
}
...
@@ -814,6 +828,7 @@ func setGetContainerLogsFunc(fw *serverTestFramework, t *testing.T, expectedPodN
...
@@ -814,6 +828,7 @@ func setGetContainerLogsFunc(fw *serverTestFramework, t *testing.T, expectedPodN
// TODO: I really want to be a table driven test
// TODO: I really want to be a table driven test
func
TestContainerLogs
(
t
*
testing
.
T
)
{
func
TestContainerLogs
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
output
:=
"foo bar"
output
:=
"foo bar"
podNamespace
:=
"other"
podNamespace
:=
"other"
podName
:=
"foo"
podName
:=
"foo"
...
@@ -839,6 +854,7 @@ func TestContainerLogs(t *testing.T) {
...
@@ -839,6 +854,7 @@ func TestContainerLogs(t *testing.T) {
func
TestContainerLogsWithLimitBytes
(
t
*
testing
.
T
)
{
func
TestContainerLogsWithLimitBytes
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
output
:=
"foo bar"
output
:=
"foo bar"
podNamespace
:=
"other"
podNamespace
:=
"other"
podName
:=
"foo"
podName
:=
"foo"
...
@@ -865,6 +881,7 @@ func TestContainerLogsWithLimitBytes(t *testing.T) {
...
@@ -865,6 +881,7 @@ func TestContainerLogsWithLimitBytes(t *testing.T) {
func
TestContainerLogsWithTail
(
t
*
testing
.
T
)
{
func
TestContainerLogsWithTail
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
output
:=
"foo bar"
output
:=
"foo bar"
podNamespace
:=
"other"
podNamespace
:=
"other"
podName
:=
"foo"
podName
:=
"foo"
...
@@ -891,6 +908,7 @@ func TestContainerLogsWithTail(t *testing.T) {
...
@@ -891,6 +908,7 @@ func TestContainerLogsWithTail(t *testing.T) {
func
TestContainerLogsWithLegacyTail
(
t
*
testing
.
T
)
{
func
TestContainerLogsWithLegacyTail
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
output
:=
"foo bar"
output
:=
"foo bar"
podNamespace
:=
"other"
podNamespace
:=
"other"
podName
:=
"foo"
podName
:=
"foo"
...
@@ -917,6 +935,7 @@ func TestContainerLogsWithLegacyTail(t *testing.T) {
...
@@ -917,6 +935,7 @@ func TestContainerLogsWithLegacyTail(t *testing.T) {
func
TestContainerLogsWithTailAll
(
t
*
testing
.
T
)
{
func
TestContainerLogsWithTailAll
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
output
:=
"foo bar"
output
:=
"foo bar"
podNamespace
:=
"other"
podNamespace
:=
"other"
podName
:=
"foo"
podName
:=
"foo"
...
@@ -942,6 +961,7 @@ func TestContainerLogsWithTailAll(t *testing.T) {
...
@@ -942,6 +961,7 @@ func TestContainerLogsWithTailAll(t *testing.T) {
func
TestContainerLogsWithInvalidTail
(
t
*
testing
.
T
)
{
func
TestContainerLogsWithInvalidTail
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
output
:=
"foo bar"
output
:=
"foo bar"
podNamespace
:=
"other"
podNamespace
:=
"other"
podName
:=
"foo"
podName
:=
"foo"
...
@@ -961,6 +981,7 @@ func TestContainerLogsWithInvalidTail(t *testing.T) {
...
@@ -961,6 +981,7 @@ func TestContainerLogsWithInvalidTail(t *testing.T) {
func
TestContainerLogsWithFollow
(
t
*
testing
.
T
)
{
func
TestContainerLogsWithFollow
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
output
:=
"foo bar"
output
:=
"foo bar"
podNamespace
:=
"other"
podNamespace
:=
"other"
podName
:=
"foo"
podName
:=
"foo"
...
@@ -986,6 +1007,7 @@ func TestContainerLogsWithFollow(t *testing.T) {
...
@@ -986,6 +1007,7 @@ func TestContainerLogsWithFollow(t *testing.T) {
func
TestServeExecInContainerIdleTimeout
(
t
*
testing
.
T
)
{
func
TestServeExecInContainerIdleTimeout
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
fw
.
fakeKubelet
.
streamingConnectionIdleTimeoutFunc
=
func
()
time
.
Duration
{
fw
.
fakeKubelet
.
streamingConnectionIdleTimeoutFunc
=
func
()
time
.
Duration
{
return
100
*
time
.
Millisecond
return
100
*
time
.
Millisecond
...
@@ -1041,6 +1063,7 @@ func testExecAttach(t *testing.T, verb string) {
...
@@ -1041,6 +1063,7 @@ func testExecAttach(t *testing.T, verb string) {
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
fw
.
fakeKubelet
.
streamingConnectionIdleTimeoutFunc
=
func
()
time
.
Duration
{
fw
.
fakeKubelet
.
streamingConnectionIdleTimeoutFunc
=
func
()
time
.
Duration
{
return
0
return
0
...
@@ -1293,6 +1316,7 @@ func TestServeAttachContainer(t *testing.T) {
...
@@ -1293,6 +1316,7 @@ func TestServeAttachContainer(t *testing.T) {
func
TestServePortForwardIdleTimeout
(
t
*
testing
.
T
)
{
func
TestServePortForwardIdleTimeout
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
fw
.
fakeKubelet
.
streamingConnectionIdleTimeoutFunc
=
func
()
time
.
Duration
{
fw
.
fakeKubelet
.
streamingConnectionIdleTimeoutFunc
=
func
()
time
.
Duration
{
return
100
*
time
.
Millisecond
return
100
*
time
.
Millisecond
...
@@ -1351,6 +1375,7 @@ func TestServePortForward(t *testing.T) {
...
@@ -1351,6 +1375,7 @@ func TestServePortForward(t *testing.T) {
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
defer
fw
.
testHTTPServer
.
Close
()
fw
.
fakeKubelet
.
streamingConnectionIdleTimeoutFunc
=
func
()
time
.
Duration
{
fw
.
fakeKubelet
.
streamingConnectionIdleTimeoutFunc
=
func
()
time
.
Duration
{
return
0
return
0
...
...
pkg/probe/http/http_test.go
View file @
5923fd35
...
@@ -121,34 +121,36 @@ func TestHTTPProbeChecker(t *testing.T) {
...
@@ -121,34 +121,36 @@ func TestHTTPProbeChecker(t *testing.T) {
},
},
}
}
for
_
,
test
:=
range
testCases
{
for
_
,
test
:=
range
testCases
{
// TODO: Close() this when fix #19254
func
()
{
server
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
server
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
test
.
handler
(
w
,
r
)
test
.
handler
(
w
,
r
)
}))
}))
u
,
err
:=
url
.
Parse
(
server
.
URL
)
defer
server
.
Close
()
if
err
!=
nil
{
u
,
err
:=
url
.
Parse
(
server
.
URL
)
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
if
err
!=
nil
{
}
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
_
,
port
,
err
:=
net
.
SplitHostPort
(
u
.
Host
)
}
if
err
!=
nil
{
_
,
port
,
err
:=
net
.
SplitHostPort
(
u
.
Host
)
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
if
err
!=
nil
{
}
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
_
,
err
=
strconv
.
Atoi
(
port
)
}
if
err
!=
nil
{
_
,
err
=
strconv
.
Atoi
(
port
)
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
if
err
!=
nil
{
}
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
health
,
output
,
err
:=
prober
.
Probe
(
u
,
test
.
reqHeaders
,
1
*
time
.
Second
)
}
if
test
.
health
==
probe
.
Unknown
&&
err
==
nil
{
health
,
output
,
err
:=
prober
.
Probe
(
u
,
test
.
reqHeaders
,
1
*
time
.
Second
)
t
.
Errorf
(
"Expected error"
)
if
test
.
health
==
probe
.
Unknown
&&
err
==
nil
{
}
t
.
Errorf
(
"Expected error"
)
if
test
.
health
!=
probe
.
Unknown
&&
err
!=
nil
{
}
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
if
test
.
health
!=
probe
.
Unknown
&&
err
!=
nil
{
}
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
if
health
!=
test
.
health
{
}
t
.
Errorf
(
"Expected %v, got %v"
,
test
.
health
,
health
)
if
health
!=
test
.
health
{
}
t
.
Errorf
(
"Expected %v, got %v"
,
test
.
health
,
health
)
if
!
containsAny
(
output
,
test
.
accBodies
)
{
}
t
.
Errorf
(
"Expected one of %#v, got %v"
,
test
.
accBodies
,
output
)
if
!
containsAny
(
output
,
test
.
accBodies
)
{
}
t
.
Errorf
(
"Expected one of %#v, got %v"
,
test
.
accBodies
,
output
)
}
}()
}
}
}
}
pkg/proxy/userspace/proxier_test.go
View file @
5923fd35
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"net/http"
"net/http"
"net/http/httptest"
"net/http/httptest"
"net/url"
"net/url"
"os"
"strconv"
"strconv"
"sync/atomic"
"sync/atomic"
"testing"
"testing"
...
@@ -85,16 +86,17 @@ func waitForClosedPortUDP(p *Proxier, proxyPort int) error {
...
@@ -85,16 +86,17 @@ func waitForClosedPortUDP(p *Proxier, proxyPort int) error {
var
tcpServerPort
int32
var
tcpServerPort
int32
var
udpServerPort
int32
var
udpServerPort
int32
func
init
(
)
{
func
TestMain
(
m
*
testing
.
M
)
{
// Don't handle panics
// Don't handle panics
runtime
.
ReallyCrash
=
true
runtime
.
ReallyCrash
=
true
// TCP setup.
// TCP setup.
// TODO: Close() this when fix #19254
tcp
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
tcp
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusOK
)
w
.
WriteHeader
(
http
.
StatusOK
)
w
.
Write
([]
byte
(
r
.
URL
.
Path
[
1
:
]))
w
.
Write
([]
byte
(
r
.
URL
.
Path
[
1
:
]))
}))
}))
defer
tcp
.
Close
()
u
,
err
:=
url
.
Parse
(
tcp
.
URL
)
u
,
err
:=
url
.
Parse
(
tcp
.
URL
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"failed to parse: %v"
,
err
))
panic
(
fmt
.
Sprintf
(
"failed to parse: %v"
,
err
))
...
@@ -124,6 +126,11 @@ func init() {
...
@@ -124,6 +126,11 @@ func init() {
}
}
udpServerPort
=
int32
(
udpServerPortValue
)
udpServerPort
=
int32
(
udpServerPortValue
)
go
udp
.
Loop
()
go
udp
.
Loop
()
ret
:=
m
.
Run
()
// it should be safe to call Close() multiple times.
tcp
.
Close
()
os
.
Exit
(
ret
)
}
}
func
testEchoTCP
(
t
*
testing
.
T
,
address
string
,
port
int
)
{
func
testEchoTCP
(
t
*
testing
.
T
,
address
string
,
port
int
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment