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
a309d3e6
Commit
a309d3e6
authored
Jun 15, 2015
by
Chao Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update pkg/api/testapi because namespace is always in the path since we remove v1beta1/2
parent
b65c321a
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
28 additions
and
84 deletions
+28
-84
testapi.go
pkg/api/testapi/testapi.go
+5
-26
testapi_test.go
pkg/api/testapi/testapi_test.go
+0
-19
handlers_test.go
pkg/apiserver/handlers_test.go
+4
-12
config_test.go
pkg/config/config_test.go
+2
-2
replication_controller_test.go
pkg/controller/replication_controller_test.go
+2
-2
endpoints_controller_test.go
pkg/service/endpoints_controller_test.go
+6
-6
factory_test.go
plugin/pkg/scheduler/factory/factory_test.go
+2
-2
auth_test.go
test/integration/auth_test.go
+7
-15
No files found.
pkg/api/testapi/testapi.go
View file @
a309d3e6
...
...
@@ -22,7 +22,6 @@ import (
"os"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
...
...
@@ -79,20 +78,17 @@ func SelfLink(resource, name string) string {
// Returns the appropriate path for the given prefix (watch, proxy, redirect, etc), resource, namespace and name.
// For ex, this is of the form:
// /api/v1beta1/watch/pods/pod0 for v1beta1 and
// /api/v1beta3/watch/namespaces/foo/pods/pod0 for v1beta3.
// /api/v1/watch/namespaces/foo/pods/pod0 for v1.
func
ResourcePathWithPrefix
(
prefix
,
resource
,
namespace
,
name
string
)
string
{
path
:=
"/api/"
+
Version
()
if
prefix
!=
""
{
path
=
path
+
"/"
+
prefix
}
if
!
api
.
PreV1Beta3
(
Version
())
{
if
namespace
!=
""
{
path
=
path
+
"/namespaces/"
+
namespace
}
// Resource names in v1beta3 are lower case.
resource
=
strings
.
ToLower
(
resource
)
if
namespace
!=
""
{
path
=
path
+
"/namespaces/"
+
namespace
}
// Resource names are lower case.
resource
=
strings
.
ToLower
(
resource
)
if
resource
!=
""
{
path
=
path
+
"/"
+
resource
}
...
...
@@ -109,20 +105,3 @@ func ResourcePathWithPrefix(prefix, resource, namespace, name string) string {
func
ResourcePath
(
resource
,
namespace
,
name
string
)
string
{
return
ResourcePathWithPrefix
(
""
,
resource
,
namespace
,
name
)
}
// Returns the appropriate path along with the query params for the given resource, namespace and name.
// For ex, this is of the form:
// /api/v1beta1/pods/pod0?namespace=foo for v1beta1 and
// /api/v1beta3/namespaces/foo/pods/pod0 for v1beta3.
func
ResourcePathWithNamespaceQuery
(
resource
,
namespace
,
name
string
)
string
{
return
ResourcePathWithPrefixAndNamespaceQuery
(
""
,
resource
,
namespace
,
name
)
}
func
ResourcePathWithPrefixAndNamespaceQuery
(
prefix
,
resource
,
namespace
,
name
string
)
string
{
path
:=
ResourcePathWithPrefix
(
prefix
,
resource
,
namespace
,
name
)
// Add namespace as query param for pre v1beta3.
if
api
.
PreV1Beta3
(
Version
())
&&
namespace
!=
""
{
path
=
path
+
"?namespace="
+
namespace
}
return
path
}
pkg/api/testapi/testapi_test.go
View file @
a309d3e6
...
...
@@ -59,22 +59,3 @@ func TestResourcePath(t *testing.T) {
}
}
}
func
TestResourcePathWithNamespaceQuery
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
resource
string
namespace
string
name
string
expected
string
}{
{
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/"
+
Version
()
+
"/namespaces/mynamespace/resource/myresource"
},
{
"resource"
,
""
,
"myresource"
,
"/api/"
+
Version
()
+
"/resource/myresource"
},
{
"resource"
,
"mynamespace"
,
""
,
"/api/"
+
Version
()
+
"/namespaces/mynamespace/resource"
},
{
"resource"
,
""
,
""
,
"/api/"
+
Version
()
+
"/resource"
},
}
for
_
,
item
:=
range
testCases
{
if
actual
:=
ResourcePathWithNamespaceQuery
(
item
.
resource
,
item
.
namespace
,
item
.
name
);
actual
!=
item
.
expected
{
t
.
Errorf
(
"Expected: %s, got: %s for resource: %s, namespace: %s and name: %s"
,
item
.
expected
,
actual
,
item
.
resource
,
item
.
namespace
,
item
.
name
)
}
}
}
pkg/apiserver/handlers_test.go
View file @
a309d3e6
...
...
@@ -53,18 +53,10 @@ func getPath(resource, namespace, name string) string {
return
testapi
.
ResourcePath
(
resource
,
namespace
,
name
)
}
func
pathWithNamespaceQuery
(
resource
,
namespace
,
name
string
)
string
{
return
testapi
.
ResourcePathWithNamespaceQuery
(
resource
,
namespace
,
name
)
}
func
pathWithPrefix
(
prefix
,
resource
,
namespace
,
name
string
)
string
{
return
testapi
.
ResourcePathWithPrefix
(
prefix
,
resource
,
namespace
,
name
)
}
func
pathWithPrefixAndNamespaceQuery
(
prefix
,
resource
,
namespace
,
name
string
)
string
{
return
testapi
.
ResourcePathWithPrefixAndNamespaceQuery
(
prefix
,
resource
,
namespace
,
name
)
}
func
TestMaxInFlight
(
t
*
testing
.
T
)
{
const
Iterations
=
3
block
:=
sync
.
WaitGroup
{}
...
...
@@ -185,15 +177,15 @@ func TestGetAPIRequestInfo(t *testing.T) {
{
"GET"
,
"/watch/namespaces/other/pods"
,
"watch"
,
""
,
"other"
,
"pods"
,
""
,
"Pod"
,
""
,
[]
string
{
"pods"
}},
// fully-qualified paths
{
"GET"
,
pathWithNamespaceQuery
(
"pods"
,
"other"
,
""
),
"list"
,
testapi
.
Version
(),
"other"
,
"pods"
,
""
,
"Pod"
,
""
,
[]
string
{
"pods"
}},
{
"GET"
,
pathWithNamespaceQuery
(
"pods"
,
"other"
,
"foo"
),
"get"
,
testapi
.
Version
(),
"other"
,
"pods"
,
""
,
"Pod"
,
"foo"
,
[]
string
{
"pods"
,
"foo"
}},
{
"GET"
,
getPath
(
"pods"
,
"other"
,
""
),
"list"
,
testapi
.
Version
(),
"other"
,
"pods"
,
""
,
"Pod"
,
""
,
[]
string
{
"pods"
}},
{
"GET"
,
getPath
(
"pods"
,
"other"
,
"foo"
),
"get"
,
testapi
.
Version
(),
"other"
,
"pods"
,
""
,
"Pod"
,
"foo"
,
[]
string
{
"pods"
,
"foo"
}},
{
"GET"
,
getPath
(
"pods"
,
""
,
""
),
"list"
,
testapi
.
Version
(),
api
.
NamespaceAll
,
"pods"
,
""
,
"Pod"
,
""
,
[]
string
{
"pods"
}},
{
"POST"
,
getPath
(
"pods"
,
""
,
""
),
"create"
,
testapi
.
Version
(),
api
.
NamespaceDefault
,
"pods"
,
""
,
"Pod"
,
""
,
[]
string
{
"pods"
}},
{
"GET"
,
getPath
(
"pods"
,
""
,
"foo"
),
"get"
,
testapi
.
Version
(),
api
.
NamespaceDefault
,
"pods"
,
""
,
"Pod"
,
"foo"
,
[]
string
{
"pods"
,
"foo"
}},
{
"GET"
,
pathWithPrefix
(
"proxy"
,
"pods"
,
""
,
"foo"
),
"proxy"
,
testapi
.
Version
(),
api
.
NamespaceDefault
,
"pods"
,
""
,
"Pod"
,
"foo"
,
[]
string
{
"pods"
,
"foo"
}},
{
"GET"
,
pathWithPrefix
(
"watch"
,
"pods"
,
""
,
""
),
"watch"
,
testapi
.
Version
(),
api
.
NamespaceAll
,
"pods"
,
""
,
"Pod"
,
""
,
[]
string
{
"pods"
}},
{
"GET"
,
pathWithPrefix
AndNamespaceQuery
(
"redirect"
,
"pods"
,
""
,
""
),
"redirect"
,
testapi
.
Version
(),
api
.
NamespaceAll
,
"pods"
,
""
,
"Pod"
,
""
,
[]
string
{
"pods"
}},
{
"GET"
,
pathWithPrefix
AndNamespaceQuery
(
"watch"
,
"pods"
,
"other"
,
""
),
"watch"
,
testapi
.
Version
(),
"other"
,
"pods"
,
""
,
"Pod"
,
""
,
[]
string
{
"pods"
}},
{
"GET"
,
pathWithPrefix
(
"redirect"
,
"pods"
,
""
,
""
),
"redirect"
,
testapi
.
Version
(),
api
.
NamespaceAll
,
"pods"
,
""
,
"Pod"
,
""
,
[]
string
{
"pods"
}},
{
"GET"
,
pathWithPrefix
(
"watch"
,
"pods"
,
"other"
,
""
),
"watch"
,
testapi
.
Version
(),
"other"
,
"pods"
,
""
,
"Pod"
,
""
,
[]
string
{
"pods"
}},
// subresource identification
{
"GET"
,
"/namespaces/other/pods/foo/status"
,
"get"
,
""
,
"other"
,
"pods"
,
"status"
,
"Pod"
,
"foo"
,
[]
string
{
"pods"
,
"foo"
,
"status"
}},
...
...
pkg/config/config_test.go
View file @
a309d3e6
...
...
@@ -67,8 +67,8 @@ func TestCreateObjects(t *testing.T) {
typer
,
mapper
:=
getTyperAndMapper
()
client
,
s
:=
getFakeClient
(
t
,
[]
string
{
testapi
.
ResourcePath
WithNamespaceQuery
(
"pods"
,
api
.
NamespaceDefault
,
""
),
testapi
.
ResourcePath
WithNamespaceQuery
(
"services"
,
api
.
NamespaceDefault
,
""
),
testapi
.
ResourcePath
(
"pods"
,
api
.
NamespaceDefault
,
""
),
testapi
.
ResourcePath
(
"services"
,
api
.
NamespaceDefault
,
""
),
})
errs
:=
CreateObjects
(
typer
,
mapper
,
client
,
items
)
...
...
pkg/controller/replication_controller_test.go
View file @
a309d3e6
...
...
@@ -328,7 +328,7 @@ func TestCreateReplica(t *testing.T) {
},
Spec
:
controllerSpec
.
Spec
.
Template
.
Spec
,
}
fakeHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
WithNamespaceQuery
(
"pods"
,
api
.
NamespaceDefault
,
""
),
"POST"
,
nil
)
fakeHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
(
"pods"
,
api
.
NamespaceDefault
,
""
),
"POST"
,
nil
)
actualPod
,
err
:=
client
.
Codec
.
Decode
([]
byte
(
fakeHandler
.
RequestBody
))
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %#v"
,
err
)
...
...
@@ -397,7 +397,7 @@ func TestControllerUpdateReplicas(t *testing.T) {
rc
.
Status
=
api
.
ReplicationControllerStatus
{
Replicas
:
4
}
decRc
:=
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
rc
)
fakeHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
WithNamespaceQuery
(
replicationControllerResourceName
(),
rc
.
Namespace
,
rc
.
Name
),
"PUT"
,
&
decRc
)
fakeHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
(
replicationControllerResourceName
(),
rc
.
Namespace
,
rc
.
Name
),
"PUT"
,
&
decRc
)
validateSyncReplication
(
t
,
&
fakePodControl
,
1
,
0
)
}
...
...
pkg/service/endpoints_controller_test.go
View file @
a309d3e6
...
...
@@ -318,7 +318,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) {
Ports
:
[]
api
.
EndpointPort
{{
Port
:
8080
,
Protocol
:
"TCP"
}},
}},
})
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
WithNamespaceQuery
(
"endpoints"
,
ns
,
"foo"
),
"PUT"
,
&
data
)
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
(
"endpoints"
,
ns
,
"foo"
),
"PUT"
,
&
data
)
}
func
TestSyncEndpointsItemsPreexisting
(
t
*
testing
.
T
)
{
...
...
@@ -358,7 +358,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) {
Ports
:
[]
api
.
EndpointPort
{{
Port
:
8080
,
Protocol
:
"TCP"
}},
}},
})
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
WithNamespaceQuery
(
"endpoints"
,
ns
,
"foo"
),
"PUT"
,
&
data
)
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
(
"endpoints"
,
ns
,
"foo"
),
"PUT"
,
&
data
)
}
func
TestSyncEndpointsItemsPreexistingIdentical
(
t
*
testing
.
T
)
{
...
...
@@ -387,7 +387,7 @@ func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) {
},
})
endpoints
.
syncService
(
ns
+
"/foo"
)
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
WithNamespaceQuery
(
"endpoints"
,
api
.
NamespaceDefault
,
"foo"
),
"GET"
,
nil
)
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
(
"endpoints"
,
api
.
NamespaceDefault
,
"foo"
),
"GET"
,
nil
)
}
func
TestSyncEndpointsItems
(
t
*
testing
.
T
)
{
...
...
@@ -429,7 +429,7 @@ func TestSyncEndpointsItems(t *testing.T) {
})
// endpointsHandler should get 2 requests - one for "GET" and the next for "POST".
endpointsHandler
.
ValidateRequestCount
(
t
,
2
)
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
WithNamespaceQuery
(
"endpoints"
,
ns
,
""
),
"POST"
,
&
data
)
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
(
"endpoints"
,
ns
,
""
),
"POST"
,
&
data
)
}
func
TestSyncEndpointsItemsWithLabels
(
t
*
testing
.
T
)
{
...
...
@@ -476,7 +476,7 @@ func TestSyncEndpointsItemsWithLabels(t *testing.T) {
})
// endpointsHandler should get 2 requests - one for "GET" and the next for "POST".
endpointsHandler
.
ValidateRequestCount
(
t
,
2
)
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
WithNamespaceQuery
(
"endpoints"
,
ns
,
""
),
"POST"
,
&
data
)
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
(
"endpoints"
,
ns
,
""
),
"POST"
,
&
data
)
}
func
TestSyncEndpointsItemsPreexistingLabelsChange
(
t
*
testing
.
T
)
{
...
...
@@ -525,5 +525,5 @@ func TestSyncEndpointsItemsPreexistingLabelsChange(t *testing.T) {
Ports
:
[]
api
.
EndpointPort
{{
Port
:
8080
,
Protocol
:
"TCP"
}},
}},
})
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
WithNamespaceQuery
(
"endpoints"
,
ns
,
"foo"
),
"PUT"
,
&
data
)
endpointsHandler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
(
"endpoints"
,
ns
,
"foo"
),
"PUT"
,
&
data
)
}
plugin/pkg/scheduler/factory/factory_test.go
View file @
a309d3e6
...
...
@@ -170,7 +170,7 @@ func TestDefaultErrorFunc(t *testing.T) {
if
!
exists
{
continue
}
handler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
WithNamespaceQuery
(
"pods"
,
"bar"
,
"foo"
),
"GET"
,
nil
)
handler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
(
"pods"
,
"bar"
,
"foo"
),
"GET"
,
nil
)
if
e
,
a
:=
testPod
,
got
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"Expected %v, got %v"
,
e
,
a
)
}
...
...
@@ -241,7 +241,7 @@ func TestBind(t *testing.T) {
continue
}
expectedBody
:=
runtime
.
EncodeOrDie
(
testapi
.
Codec
(),
item
.
binding
)
handler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
WithNamespaceQuery
(
"bindings"
,
api
.
NamespaceDefault
,
""
),
"POST"
,
&
expectedBody
)
handler
.
ValidateRequest
(
t
,
testapi
.
ResourcePath
(
"bindings"
,
api
.
NamespaceDefault
,
""
),
"POST"
,
&
expectedBody
)
}
}
...
...
test/integration/auth_test.go
View file @
a309d3e6
...
...
@@ -78,10 +78,6 @@ func path(resource, namespace, name string) string {
return
testapi
.
ResourcePath
(
resource
,
namespace
,
name
)
}
func
pathWithNamespaceQuery
(
resource
,
namespace
,
name
string
)
string
{
return
testapi
.
ResourcePathWithNamespaceQuery
(
resource
,
namespace
,
name
)
}
func
pathWithPrefix
(
prefix
,
resource
,
namespace
,
name
string
)
string
{
return
testapi
.
ResourcePathWithPrefix
(
prefix
,
resource
,
namespace
,
name
)
}
...
...
@@ -90,10 +86,6 @@ func timeoutPath(resource, namespace, name string) string {
return
addTimeoutFlag
(
testapi
.
ResourcePath
(
resource
,
namespace
,
name
))
}
func
timeoutPathWithNamespaceQuery
(
resource
,
namespace
,
name
string
)
string
{
return
addTimeoutFlag
(
testapi
.
ResourcePathWithNamespaceQuery
(
resource
,
namespace
,
name
))
}
// Bodies for requests used in subsequent tests.
var
aPod
string
=
`
{
...
...
@@ -846,15 +838,15 @@ func TestNamespaceAuthorization(t *testing.T) {
statusCodes
map
[
int
]
bool
// allowed status codes.
}{
{
"POST"
,
timeoutPath
WithNamespaceQuery
(
"pods"
,
"foo"
,
""
),
"foo"
,
aPod
,
code201
},
{
"GET"
,
path
WithNamespaceQuery
(
"pods"
,
"foo"
,
""
),
"foo"
,
""
,
code200
},
{
"GET"
,
path
WithNamespaceQuery
(
"pods"
,
"foo"
,
"a"
),
"foo"
,
""
,
code200
},
{
"DELETE"
,
timeoutPath
WithNamespaceQuery
(
"pods"
,
"foo"
,
"a"
),
"foo"
,
""
,
code200
},
{
"POST"
,
timeoutPath
(
"pods"
,
"foo"
,
""
),
"foo"
,
aPod
,
code201
},
{
"GET"
,
path
(
"pods"
,
"foo"
,
""
),
"foo"
,
""
,
code200
},
{
"GET"
,
path
(
"pods"
,
"foo"
,
"a"
),
"foo"
,
""
,
code200
},
{
"DELETE"
,
timeoutPath
(
"pods"
,
"foo"
,
"a"
),
"foo"
,
""
,
code200
},
{
"POST"
,
timeoutPath
(
"pods"
,
"bar"
,
""
),
"bar"
,
aPod
,
code403
},
{
"GET"
,
path
WithNamespaceQuery
(
"pods"
,
"bar"
,
""
),
"bar"
,
""
,
code403
},
{
"GET"
,
path
WithNamespaceQuery
(
"pods"
,
"bar"
,
"a"
),
"bar"
,
""
,
code403
},
{
"DELETE"
,
timeoutPath
WithNamespaceQuery
(
"pods"
,
"bar"
,
"a"
),
"bar"
,
""
,
code403
},
{
"GET"
,
path
(
"pods"
,
"bar"
,
""
),
"bar"
,
""
,
code403
},
{
"GET"
,
path
(
"pods"
,
"bar"
,
"a"
),
"bar"
,
""
,
code403
},
{
"DELETE"
,
timeoutPath
(
"pods"
,
"bar"
,
"a"
),
"bar"
,
""
,
code403
},
{
"POST"
,
timeoutPath
(
"pods"
,
api
.
NamespaceDefault
,
""
),
""
,
aPod
,
code403
},
{
"GET"
,
path
(
"pods"
,
""
,
""
),
""
,
""
,
code403
},
...
...
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