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
df77b729
Unverified
Commit
df77b729
authored
Jan 08, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Jan 08, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70886 from bouk/patch-missing-object
client-go/testing: properly handle Patch actions for missing Objects
parents
1b28775d
96d05884
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
2 deletions
+17
-2
BUILD
staging/src/k8s.io/client-go/testing/BUILD
+1
-0
fixture.go
staging/src/k8s.io/client-go/testing/fixture.go
+1
-2
fixture_test.go
staging/src/k8s.io/client-go/testing/fixture_test.go
+15
-0
No files found.
staging/src/k8s.io/client-go/testing/BUILD
View file @
df77b729
...
@@ -42,6 +42,7 @@ go_test(
...
@@ -42,6 +42,7 @@ go_test(
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
],
],
...
...
staging/src/k8s.io/client-go/testing/fixture.go
View file @
df77b729
...
@@ -131,8 +131,7 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
...
@@ -131,8 +131,7 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
case
PatchActionImpl
:
case
PatchActionImpl
:
obj
,
err
:=
tracker
.
Get
(
gvr
,
ns
,
action
.
GetName
())
obj
,
err
:=
tracker
.
Get
(
gvr
,
ns
,
action
.
GetName
())
if
err
!=
nil
{
if
err
!=
nil
{
// object is not registered
return
true
,
nil
,
err
return
false
,
nil
,
err
}
}
old
,
err
:=
json
.
Marshal
(
obj
)
old
,
err
:=
json
.
Marshal
(
obj
)
...
...
staging/src/k8s.io/client-go/testing/fixture_test.go
View file @
df77b729
...
@@ -30,6 +30,7 @@ import (
...
@@ -30,6 +30,7 @@ import (
runtime
"k8s.io/apimachinery/pkg/runtime"
runtime
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
serializer
"k8s.io/apimachinery/pkg/runtime/serializer"
serializer
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/apimachinery/pkg/watch"
)
)
...
@@ -258,3 +259,17 @@ func TestWatchAddAfterStop(t *testing.T) {
...
@@ -258,3 +259,17 @@ func TestWatchAddAfterStop(t *testing.T) {
t
.
Errorf
(
"test resource creation failed: %v"
,
err
)
t
.
Errorf
(
"test resource creation failed: %v"
,
err
)
}
}
}
}
func
TestPatchWithMissingObject
(
t
*
testing
.
T
)
{
nodesResource
:=
schema
.
GroupVersionResource
{
Group
:
""
,
Version
:
"v1"
,
Resource
:
"nodes"
}
scheme
:=
runtime
.
NewScheme
()
codecs
:=
serializer
.
NewCodecFactory
(
scheme
)
o
:=
NewObjectTracker
(
scheme
,
codecs
.
UniversalDecoder
())
reaction
:=
ObjectReaction
(
o
)
action
:=
NewRootPatchSubresourceAction
(
nodesResource
,
"node-1"
,
types
.
StrategicMergePatchType
,
[]
byte
(
`{}`
))
handled
,
node
,
err
:=
reaction
(
action
)
assert
.
True
(
t
,
handled
)
assert
.
Nil
(
t
,
node
)
assert
.
EqualError
(
t
,
err
,
`nodes "node-1" not found`
)
}
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