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
8341c48b
Commit
8341c48b
authored
Apr 18, 2018
by
Antoine Pelisse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apiserver: move patch tests to their own file
parent
214ce657
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
70 deletions
+100
-70
BUILD
staging/src/k8s.io/apiserver/pkg/endpoints/BUILD
+1
-0
apiserver_test.go
staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go
+0
-70
patchhandler_test.go
...g/src/k8s.io/apiserver/pkg/endpoints/patchhandler_test.go
+99
-0
No files found.
staging/src/k8s.io/apiserver/pkg/endpoints/BUILD
View file @
8341c48b
...
@@ -12,6 +12,7 @@ go_test(
...
@@ -12,6 +12,7 @@ go_test(
"apiserver_test.go",
"apiserver_test.go",
"audit_test.go",
"audit_test.go",
"installer_test.go",
"installer_test.go",
"patchhandler_test.go",
"watch_test.go",
"watch_test.go",
],
],
embed = [":go_default_library"],
embed = [":go_default_library"],
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go
View file @
8341c48b
...
@@ -2887,76 +2887,6 @@ func TestDeleteMissing(t *testing.T) {
...
@@ -2887,76 +2887,6 @@ func TestDeleteMissing(t *testing.T) {
}
}
}
}
func
TestPatch
(
t
*
testing
.
T
)
{
storage
:=
map
[
string
]
rest
.
Storage
{}
ID
:=
"id"
item
:=
&
genericapitesting
.
Simple
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
ID
,
Namespace
:
""
,
// update should allow the client to send an empty namespace
UID
:
"uid"
,
},
Other
:
"bar"
,
}
simpleStorage
:=
SimpleRESTStorage
{
item
:
*
item
}
storage
[
"simple"
]
=
&
simpleStorage
selfLinker
:=
&
setTestSelfLinker
{
t
:
t
,
expectedSet
:
"/"
+
prefix
+
"/"
+
testGroupVersion
.
Group
+
"/"
+
testGroupVersion
.
Version
+
"/namespaces/default/simple/"
+
ID
,
name
:
ID
,
namespace
:
metav1
.
NamespaceDefault
,
}
handler
:=
handleLinker
(
storage
,
selfLinker
)
server
:=
httptest
.
NewServer
(
handler
)
defer
server
.
Close
()
client
:=
http
.
Client
{}
request
,
err
:=
http
.
NewRequest
(
"PATCH"
,
server
.
URL
+
"/"
+
prefix
+
"/"
+
testGroupVersion
.
Group
+
"/"
+
testGroupVersion
.
Version
+
"/namespaces/default/simple/"
+
ID
,
bytes
.
NewReader
([]
byte
(
`{"labels":{"foo":"bar"}}`
)))
request
.
Header
.
Set
(
"Content-Type"
,
"application/merge-patch+json; charset=UTF-8"
)
response
,
err
:=
client
.
Do
(
request
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
dump
,
_
:=
httputil
.
DumpResponse
(
response
,
true
)
t
.
Log
(
string
(
dump
))
if
simpleStorage
.
updated
==
nil
||
simpleStorage
.
updated
.
Labels
[
"foo"
]
!=
"bar"
{
t
.
Errorf
(
"Unexpected update value %#v, expected %#v."
,
simpleStorage
.
updated
,
item
)
}
if
!
selfLinker
.
called
{
t
.
Errorf
(
"Never set self link"
)
}
}
func
TestPatchRequiresMatchingName
(
t
*
testing
.
T
)
{
storage
:=
map
[
string
]
rest
.
Storage
{}
ID
:=
"id"
item
:=
&
genericapitesting
.
Simple
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
ID
,
Namespace
:
""
,
// update should allow the client to send an empty namespace
UID
:
"uid"
,
},
Other
:
"bar"
,
}
simpleStorage
:=
SimpleRESTStorage
{
item
:
*
item
}
storage
[
"simple"
]
=
&
simpleStorage
handler
:=
handle
(
storage
)
server
:=
httptest
.
NewServer
(
handler
)
defer
server
.
Close
()
client
:=
http
.
Client
{}
request
,
err
:=
http
.
NewRequest
(
"PATCH"
,
server
.
URL
+
"/"
+
prefix
+
"/"
+
testGroupVersion
.
Group
+
"/"
+
testGroupVersion
.
Version
+
"/namespaces/default/simple/"
+
ID
,
bytes
.
NewReader
([]
byte
(
`{"metadata":{"name":"idbar"}}`
)))
request
.
Header
.
Set
(
"Content-Type"
,
"application/merge-patch+json"
)
response
,
err
:=
client
.
Do
(
request
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
if
response
.
StatusCode
!=
http
.
StatusBadRequest
{
t
.
Errorf
(
"Unexpected response %#v"
,
response
)
}
}
func
TestUpdate
(
t
*
testing
.
T
)
{
func
TestUpdate
(
t
*
testing
.
T
)
{
storage
:=
map
[
string
]
rest
.
Storage
{}
storage
:=
map
[
string
]
rest
.
Storage
{}
simpleStorage
:=
SimpleRESTStorage
{}
simpleStorage
:=
SimpleRESTStorage
{}
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/patchhandler_test.go
0 → 100644
View file @
8341c48b
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
endpoints
import
(
"bytes"
"net/http"
"net/http/httptest"
"net/http/httputil"
"testing"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
genericapitesting
"k8s.io/apiserver/pkg/endpoints/testing"
"k8s.io/apiserver/pkg/registry/rest"
)
func
TestPatch
(
t
*
testing
.
T
)
{
storage
:=
map
[
string
]
rest
.
Storage
{}
ID
:=
"id"
item
:=
&
genericapitesting
.
Simple
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
ID
,
Namespace
:
""
,
// update should allow the client to send an empty namespace
UID
:
"uid"
,
},
Other
:
"bar"
,
}
simpleStorage
:=
SimpleRESTStorage
{
item
:
*
item
}
storage
[
"simple"
]
=
&
simpleStorage
selfLinker
:=
&
setTestSelfLinker
{
t
:
t
,
expectedSet
:
"/"
+
prefix
+
"/"
+
testGroupVersion
.
Group
+
"/"
+
testGroupVersion
.
Version
+
"/namespaces/default/simple/"
+
ID
,
name
:
ID
,
namespace
:
metav1
.
NamespaceDefault
,
}
handler
:=
handleLinker
(
storage
,
selfLinker
)
server
:=
httptest
.
NewServer
(
handler
)
defer
server
.
Close
()
client
:=
http
.
Client
{}
request
,
err
:=
http
.
NewRequest
(
"PATCH"
,
server
.
URL
+
"/"
+
prefix
+
"/"
+
testGroupVersion
.
Group
+
"/"
+
testGroupVersion
.
Version
+
"/namespaces/default/simple/"
+
ID
,
bytes
.
NewReader
([]
byte
(
`{"labels":{"foo":"bar"}}`
)))
request
.
Header
.
Set
(
"Content-Type"
,
"application/merge-patch+json; charset=UTF-8"
)
response
,
err
:=
client
.
Do
(
request
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
dump
,
_
:=
httputil
.
DumpResponse
(
response
,
true
)
t
.
Log
(
string
(
dump
))
if
simpleStorage
.
updated
==
nil
||
simpleStorage
.
updated
.
Labels
[
"foo"
]
!=
"bar"
{
t
.
Errorf
(
"Unexpected update value %#v, expected %#v."
,
simpleStorage
.
updated
,
item
)
}
if
!
selfLinker
.
called
{
t
.
Errorf
(
"Never set self link"
)
}
}
func
TestPatchRequiresMatchingName
(
t
*
testing
.
T
)
{
storage
:=
map
[
string
]
rest
.
Storage
{}
ID
:=
"id"
item
:=
&
genericapitesting
.
Simple
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
ID
,
Namespace
:
""
,
// update should allow the client to send an empty namespace
UID
:
"uid"
,
},
Other
:
"bar"
,
}
simpleStorage
:=
SimpleRESTStorage
{
item
:
*
item
}
storage
[
"simple"
]
=
&
simpleStorage
handler
:=
handle
(
storage
)
server
:=
httptest
.
NewServer
(
handler
)
defer
server
.
Close
()
client
:=
http
.
Client
{}
request
,
err
:=
http
.
NewRequest
(
"PATCH"
,
server
.
URL
+
"/"
+
prefix
+
"/"
+
testGroupVersion
.
Group
+
"/"
+
testGroupVersion
.
Version
+
"/namespaces/default/simple/"
+
ID
,
bytes
.
NewReader
([]
byte
(
`{"metadata":{"name":"idbar"}}`
)))
request
.
Header
.
Set
(
"Content-Type"
,
"application/merge-patch+json"
)
response
,
err
:=
client
.
Do
(
request
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
if
response
.
StatusCode
!=
http
.
StatusBadRequest
{
t
.
Errorf
(
"Unexpected response %#v"
,
response
)
}
}
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