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
bda1c76f
Commit
bda1c76f
authored
Sep 28, 2016
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify genericapiserver tests
parent
9e1960c5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
19 deletions
+15
-19
genericapiserver_test.go
pkg/genericapiserver/genericapiserver_test.go
+15
-19
No files found.
pkg/genericapiserver/genericapiserver_test.go
View file @
bda1c76f
...
@@ -46,25 +46,24 @@ import (
...
@@ -46,25 +46,24 @@ import (
)
)
// setUp is a convience function for setting up for (most) tests.
// setUp is a convience function for setting up for (most) tests.
func
setUp
(
t
*
testing
.
T
)
(
*
GenericAPIServer
,
*
etcdtesting
.
EtcdTestServer
,
Config
,
*
assert
.
Assertions
)
{
func
setUp
(
t
*
testing
.
T
)
(
*
etcdtesting
.
EtcdTestServer
,
Config
,
*
assert
.
Assertions
)
{
etcdServer
,
_
:=
etcdtesting
.
NewUnsecuredEtcd3TestClientServer
(
t
)
etcdServer
,
_
:=
etcdtesting
.
NewUnsecuredEtcd3TestClientServer
(
t
)
genericapiserver
:=
&
GenericAPIServer
{}
config
:=
Config
{}
config
:=
Config
{}
config
.
PublicAddress
=
net
.
ParseIP
(
"192.168.10.4"
)
config
.
PublicAddress
=
net
.
ParseIP
(
"192.168.10.4"
)
config
.
RequestContextMapper
=
api
.
NewRequestContextMapper
()
config
.
RequestContextMapper
=
api
.
NewRequestContextMapper
()
return
genericapiserver
,
etcdServer
,
config
,
assert
.
New
(
t
)
}
func
newMaster
(
t
*
testing
.
T
)
(
*
GenericAPIServer
,
*
etcdtesting
.
EtcdTestServer
,
Config
,
*
assert
.
Assertions
)
{
_
,
etcdserver
,
config
,
assert
:=
setUp
(
t
)
config
.
ProxyDialer
=
func
(
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
nil
,
nil
}
config
.
ProxyDialer
=
func
(
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
nil
,
nil
}
config
.
ProxyTLSClientConfig
=
&
tls
.
Config
{}
config
.
ProxyTLSClientConfig
=
&
tls
.
Config
{}
config
.
Serializer
=
api
.
Codecs
config
.
Serializer
=
api
.
Codecs
config
.
APIPrefix
=
"/api"
config
.
APIPrefix
=
"/api"
config
.
APIGroupPrefix
=
"/apis"
config
.
APIGroupPrefix
=
"/apis"
return
etcdServer
,
config
,
assert
.
New
(
t
)
}
func
newMaster
(
t
*
testing
.
T
)
(
*
GenericAPIServer
,
*
etcdtesting
.
EtcdTestServer
,
Config
,
*
assert
.
Assertions
)
{
etcdserver
,
config
,
assert
:=
setUp
(
t
)
s
,
err
:=
config
.
New
()
s
,
err
:=
config
.
New
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Error in bringing up the server: %v"
,
err
)
t
.
Fatalf
(
"Error in bringing up the server: %v"
,
err
)
...
@@ -104,14 +103,11 @@ func TestNew(t *testing.T) {
...
@@ -104,14 +103,11 @@ func TestNew(t *testing.T) {
// Verifies that AddGroupVersions works as expected.
// Verifies that AddGroupVersions works as expected.
func
TestInstallAPIGroups
(
t
*
testing
.
T
)
{
func
TestInstallAPIGroups
(
t
*
testing
.
T
)
{
_
,
etcdserver
,
config
,
assert
:=
setUp
(
t
)
etcdserver
,
config
,
assert
:=
setUp
(
t
)
defer
etcdserver
.
Terminate
(
t
)
defer
etcdserver
.
Terminate
(
t
)
config
.
ProxyDialer
=
func
(
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
nil
,
nil
}
config
.
ProxyTLSClientConfig
=
&
tls
.
Config
{}
config
.
APIPrefix
=
"/apiPrefix"
config
.
APIPrefix
=
"/apiPrefix"
config
.
APIGroupPrefix
=
"/apiGroupPrefix"
config
.
APIGroupPrefix
=
"/apiGroupPrefix"
config
.
Serializer
=
api
.
Codecs
s
,
err
:=
config
.
New
()
s
,
err
:=
config
.
New
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -174,9 +170,10 @@ func TestNewHandlerContainer(t *testing.T) {
...
@@ -174,9 +170,10 @@ func TestNewHandlerContainer(t *testing.T) {
// TestHandleWithAuth verifies HandleWithAuth adds the path
// TestHandleWithAuth verifies HandleWithAuth adds the path
// to the MuxHelper.RegisteredPaths.
// to the MuxHelper.RegisteredPaths.
func
TestHandleWithAuth
(
t
*
testing
.
T
)
{
func
TestHandleWithAuth
(
t
*
testing
.
T
)
{
server
,
etcdserver
,
_
,
assert
:=
setUp
(
t
)
etcdserver
,
_
,
assert
:=
setUp
(
t
)
defer
etcdserver
.
Terminate
(
t
)
defer
etcdserver
.
Terminate
(
t
)
server
:=
&
GenericAPIServer
{}
server
.
Mux
=
apiserver
.
NewPathRecorderMux
(
http
.
NewServeMux
())
server
.
Mux
=
apiserver
.
NewPathRecorderMux
(
http
.
NewServeMux
())
handler
:=
func
(
r
http
.
ResponseWriter
,
w
*
http
.
Request
)
{
w
.
Write
(
nil
)
}
handler
:=
func
(
r
http
.
ResponseWriter
,
w
*
http
.
Request
)
{
w
.
Write
(
nil
)
}
server
.
HandleWithAuth
(
"/test"
,
http
.
HandlerFunc
(
handler
))
server
.
HandleWithAuth
(
"/test"
,
http
.
HandlerFunc
(
handler
))
...
@@ -187,9 +184,10 @@ func TestHandleWithAuth(t *testing.T) {
...
@@ -187,9 +184,10 @@ func TestHandleWithAuth(t *testing.T) {
// TestHandleFuncWithAuth verifies HandleFuncWithAuth adds the path
// TestHandleFuncWithAuth verifies HandleFuncWithAuth adds the path
// to the MuxHelper.RegisteredPaths.
// to the MuxHelper.RegisteredPaths.
func
TestHandleFuncWithAuth
(
t
*
testing
.
T
)
{
func
TestHandleFuncWithAuth
(
t
*
testing
.
T
)
{
server
,
etcdserver
,
_
,
assert
:=
setUp
(
t
)
etcdserver
,
_
,
assert
:=
setUp
(
t
)
defer
etcdserver
.
Terminate
(
t
)
defer
etcdserver
.
Terminate
(
t
)
server
:=
&
GenericAPIServer
{}
server
.
Mux
=
apiserver
.
NewPathRecorderMux
(
http
.
NewServeMux
())
server
.
Mux
=
apiserver
.
NewPathRecorderMux
(
http
.
NewServeMux
())
handler
:=
func
(
r
http
.
ResponseWriter
,
w
*
http
.
Request
)
{
w
.
Write
(
nil
)
}
handler
:=
func
(
r
http
.
ResponseWriter
,
w
*
http
.
Request
)
{
w
.
Write
(
nil
)
}
server
.
HandleFuncWithAuth
(
"/test"
,
handler
)
server
.
HandleFuncWithAuth
(
"/test"
,
handler
)
...
@@ -199,16 +197,13 @@ func TestHandleFuncWithAuth(t *testing.T) {
...
@@ -199,16 +197,13 @@ func TestHandleFuncWithAuth(t *testing.T) {
// TestNotRestRoutesHaveAuth checks that special non-routes are behind authz/authn.
// TestNotRestRoutesHaveAuth checks that special non-routes are behind authz/authn.
func
TestNotRestRoutesHaveAuth
(
t
*
testing
.
T
)
{
func
TestNotRestRoutesHaveAuth
(
t
*
testing
.
T
)
{
_
,
etcdserver
,
config
,
_
:=
setUp
(
t
)
etcdserver
,
config
,
_
:=
setUp
(
t
)
defer
etcdserver
.
Terminate
(
t
)
defer
etcdserver
.
Terminate
(
t
)
authz
:=
mockAuthorizer
{}
authz
:=
mockAuthorizer
{}
config
.
ProxyDialer
=
func
(
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
nil
,
nil
}
config
.
ProxyTLSClientConfig
=
&
tls
.
Config
{}
config
.
APIPrefix
=
"/apiPrefix"
config
.
APIPrefix
=
"/apiPrefix"
config
.
APIGroupPrefix
=
"/apiGroupPrefix"
config
.
APIGroupPrefix
=
"/apiGroupPrefix"
config
.
Serializer
=
api
.
Codecs
config
.
Authorizer
=
&
authz
config
.
Authorizer
=
&
authz
config
.
EnableSwaggerUI
=
true
config
.
EnableSwaggerUI
=
true
...
@@ -267,10 +262,11 @@ func (authn *mockAuthenticator) AuthenticateRequest(req *http.Request) (user.Inf
...
@@ -267,10 +262,11 @@ func (authn *mockAuthenticator) AuthenticateRequest(req *http.Request) (user.Inf
// TestInstallSwaggerAPI verifies that the swagger api is added
// TestInstallSwaggerAPI verifies that the swagger api is added
// at the proper endpoint.
// at the proper endpoint.
func
TestInstallSwaggerAPI
(
t
*
testing
.
T
)
{
func
TestInstallSwaggerAPI
(
t
*
testing
.
T
)
{
server
,
etcdserver
,
_
,
assert
:=
setUp
(
t
)
etcdserver
,
_
,
assert
:=
setUp
(
t
)
defer
etcdserver
.
Terminate
(
t
)
defer
etcdserver
.
Terminate
(
t
)
mux
:=
http
.
NewServeMux
()
mux
:=
http
.
NewServeMux
()
server
:=
&
GenericAPIServer
{}
server
.
HandlerContainer
=
NewHandlerContainer
(
mux
,
nil
)
server
.
HandlerContainer
=
NewHandlerContainer
(
mux
,
nil
)
// Ensure swagger isn't installed without the call
// Ensure swagger isn't installed without the call
...
...
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