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
4cc63313
Commit
4cc63313
authored
Sep 28, 2015
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix testclient prepend functions
parent
7b428d8b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
17 deletions
+21
-17
testclient.go
pkg/client/unversioned/testclient/testclient.go
+13
-3
controller_test.go
pkg/controller/job/controller_test.go
+4
-4
replication_controller_test.go
pkg/controller/replication/replication_controller_test.go
+1
-4
admission_test.go
plugin/pkg/admission/namespace/lifecycle/admission_test.go
+3
-6
No files found.
pkg/client/unversioned/testclient/testclient.go
View file @
4cc63313
...
...
@@ -40,6 +40,8 @@ func NewSimpleFake(objects ...runtime.Object) *Fake {
fakeClient
:=
&
Fake
{}
fakeClient
.
AddReactor
(
"*"
,
"*"
,
ObjectReaction
(
o
,
api
.
RESTMapper
))
fakeClient
.
AddWatchReactor
(
"*"
,
DefaultWatchReactor
(
watch
.
NewFake
(),
nil
))
return
fakeClient
}
...
...
@@ -100,9 +102,7 @@ func (c *Fake) AddReactor(verb, resource string, reaction ReactionFunc) {
// PrependReactor adds a reactor to the beginning of the chain
func
(
c
*
Fake
)
PrependReactor
(
verb
,
resource
string
,
reaction
ReactionFunc
)
{
newChain
:=
make
([]
Reactor
,
0
,
len
(
c
.
ReactionChain
)
+
1
)
newChain
[
0
]
=
&
SimpleReactor
{
verb
,
resource
,
reaction
}
newChain
=
append
(
newChain
,
c
.
ReactionChain
...
)
c
.
ReactionChain
=
append
([]
Reactor
{
&
SimpleReactor
{
verb
,
resource
,
reaction
}},
c
.
ReactionChain
...
)
}
// AddWatchReactor appends a reactor to the end of the chain
...
...
@@ -110,11 +110,21 @@ func (c *Fake) AddWatchReactor(resource string, reaction WatchReactionFunc) {
c
.
WatchReactionChain
=
append
(
c
.
WatchReactionChain
,
&
SimpleWatchReactor
{
resource
,
reaction
})
}
// PrependWatchReactor adds a reactor to the beginning of the chain
func
(
c
*
Fake
)
PrependWatchReactor
(
resource
string
,
reaction
WatchReactionFunc
)
{
c
.
WatchReactionChain
=
append
([]
WatchReactor
{
&
SimpleWatchReactor
{
resource
,
reaction
}},
c
.
WatchReactionChain
...
)
}
// AddProxyReactor appends a reactor to the end of the chain
func
(
c
*
Fake
)
AddProxyReactor
(
resource
string
,
reaction
ProxyReactionFunc
)
{
c
.
ProxyReactionChain
=
append
(
c
.
ProxyReactionChain
,
&
SimpleProxyReactor
{
resource
,
reaction
})
}
// PrependProxyReactor adds a reactor to the beginning of the chain
func
(
c
*
Fake
)
PrependProxyReactor
(
resource
string
,
reaction
ProxyReactionFunc
)
{
c
.
ProxyReactionChain
=
append
([]
ProxyReactor
{
&
SimpleProxyReactor
{
resource
,
reaction
}},
c
.
ProxyReactionChain
...
)
}
// Invokes records the provided Action and then invokes the ReactFn (if provided).
// defaultReturnObj is expected to be of the same type a normal call would return.
func
(
c
*
Fake
)
Invokes
(
action
Action
,
defaultReturnObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
...
...
pkg/controller/job/controller_test.go
View file @
4cc63313
...
...
@@ -395,9 +395,9 @@ type FakeWatcher struct {
}
func
TestWatchJobs
(
t
*
testing
.
T
)
{
client
:=
testclient
.
NewSimpleFake
()
fakeWatch
:=
watch
.
NewFake
()
client
:=
&
testclient
.
Fake
{}
client
.
AddWatchReactor
(
"*"
,
testclient
.
DefaultWatchReactor
(
fakeWatch
,
nil
))
client
.
PrependWatchReactor
(
"*"
,
testclient
.
DefaultWatchReactor
(
fakeWatch
,
nil
))
manager
:=
NewJobController
(
client
)
manager
.
podStoreSynced
=
alwaysReady
...
...
@@ -458,9 +458,9 @@ func TestWatchJobs(t *testing.T) {
}
func
TestWatchPods
(
t
*
testing
.
T
)
{
client
:=
testclient
.
NewSimpleFake
()
fakeWatch
:=
watch
.
NewFake
()
client
:=
&
testclient
.
Fake
{}
client
.
AddWatchReactor
(
"*"
,
testclient
.
DefaultWatchReactor
(
fakeWatch
,
nil
))
client
.
PrependWatchReactor
(
"*"
,
testclient
.
DefaultWatchReactor
(
fakeWatch
,
nil
))
manager
:=
NewJobController
(
client
)
manager
.
podStoreSynced
=
alwaysReady
...
...
pkg/controller/replication/replication_controller_test.go
View file @
4cc63313
...
...
@@ -502,10 +502,7 @@ func TestWatchPods(t *testing.T) {
}
func
TestUpdatePods
(
t
*
testing
.
T
)
{
fakeWatch
:=
watch
.
NewFake
()
client
:=
&
testclient
.
Fake
{}
client
.
AddWatchReactor
(
"*"
,
testclient
.
DefaultWatchReactor
(
fakeWatch
,
nil
))
manager
:=
NewReplicationManager
(
client
,
BurstReplicas
)
manager
:=
NewReplicationManager
(
testclient
.
NewSimpleFake
(),
BurstReplicas
)
manager
.
podStoreSynced
=
alwaysReady
received
:=
make
(
chan
string
)
...
...
plugin/pkg/admission/namespace/lifecycle/admission_test.go
View file @
4cc63313
...
...
@@ -26,7 +26,6 @@ import (
"k8s.io/kubernetes/pkg/client/cache"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/watch"
)
// TestAdmission
...
...
@@ -44,10 +43,8 @@ func TestAdmission(t *testing.T) {
store
:=
cache
.
NewStore
(
cache
.
MetaNamespaceKeyFunc
)
store
.
Add
(
namespaceObj
)
fakeWatch
:=
watch
.
NewFake
()
mockClient
:=
&
testclient
.
Fake
{}
mockClient
.
AddWatchReactor
(
"*"
,
testclient
.
DefaultWatchReactor
(
fakeWatch
,
nil
))
mockClient
.
AddReactor
(
"get"
,
"namespaces"
,
func
(
action
testclient
.
Action
)
(
bool
,
runtime
.
Object
,
error
)
{
mockClient
:=
testclient
.
NewSimpleFake
()
mockClient
.
PrependReactor
(
"get"
,
"namespaces"
,
func
(
action
testclient
.
Action
)
(
bool
,
runtime
.
Object
,
error
)
{
namespaceLock
.
RLock
()
defer
namespaceLock
.
RUnlock
()
if
getAction
,
ok
:=
action
.
(
testclient
.
GetAction
);
ok
&&
getAction
.
GetName
()
==
namespaceObj
.
Name
{
...
...
@@ -55,7 +52,7 @@ func TestAdmission(t *testing.T) {
}
return
true
,
nil
,
fmt
.
Errorf
(
"No result for action %v"
,
action
)
})
mockClient
.
Ad
dReactor
(
"list"
,
"namespaces"
,
func
(
action
testclient
.
Action
)
(
bool
,
runtime
.
Object
,
error
)
{
mockClient
.
Prepen
dReactor
(
"list"
,
"namespaces"
,
func
(
action
testclient
.
Action
)
(
bool
,
runtime
.
Object
,
error
)
{
namespaceLock
.
RLock
()
defer
namespaceLock
.
RUnlock
()
return
true
,
&
api
.
NamespaceList
{
Items
:
[]
api
.
Namespace
{
*
namespaceObj
}},
nil
...
...
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