mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #14664 from deads2k/fix-prepend
Auto commit by PR queue bot
This commit is contained in:
commit
562ea7160d
@ -42,6 +42,8 @@ func NewSimpleFake(objects ...runtime.Object) *Fake {
|
|||||||
fakeClient := &Fake{}
|
fakeClient := &Fake{}
|
||||||
fakeClient.AddReactor("*", "*", ObjectReaction(o, api.RESTMapper))
|
fakeClient.AddReactor("*", "*", ObjectReaction(o, api.RESTMapper))
|
||||||
|
|
||||||
|
fakeClient.AddWatchReactor("*", DefaultWatchReactor(watch.NewFake(), nil))
|
||||||
|
|
||||||
return fakeClient
|
return fakeClient
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,9 +104,7 @@ func (c *Fake) AddReactor(verb, resource string, reaction ReactionFunc) {
|
|||||||
|
|
||||||
// PrependReactor adds a reactor to the beginning of the chain
|
// PrependReactor adds a reactor to the beginning of the chain
|
||||||
func (c *Fake) PrependReactor(verb, resource string, reaction ReactionFunc) {
|
func (c *Fake) PrependReactor(verb, resource string, reaction ReactionFunc) {
|
||||||
newChain := make([]Reactor, 0, len(c.ReactionChain)+1)
|
c.ReactionChain = append([]Reactor{&SimpleReactor{verb, resource, reaction}}, c.ReactionChain...)
|
||||||
newChain[0] = &SimpleReactor{verb, resource, reaction}
|
|
||||||
newChain = append(newChain, c.ReactionChain...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddWatchReactor appends a reactor to the end of the chain
|
// AddWatchReactor appends a reactor to the end of the chain
|
||||||
@ -112,11 +112,21 @@ func (c *Fake) AddWatchReactor(resource string, reaction WatchReactionFunc) {
|
|||||||
c.WatchReactionChain = append(c.WatchReactionChain, &SimpleWatchReactor{resource, reaction})
|
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
|
// AddProxyReactor appends a reactor to the end of the chain
|
||||||
func (c *Fake) AddProxyReactor(resource string, reaction ProxyReactionFunc) {
|
func (c *Fake) AddProxyReactor(resource string, reaction ProxyReactionFunc) {
|
||||||
c.ProxyReactionChain = append(c.ProxyReactionChain, &SimpleProxyReactor{resource, reaction})
|
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).
|
// 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.
|
// 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) {
|
func (c *Fake) Invokes(action Action, defaultReturnObj runtime.Object) (runtime.Object, error) {
|
||||||
|
@ -395,9 +395,9 @@ type FakeWatcher struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchJobs(t *testing.T) {
|
func TestWatchJobs(t *testing.T) {
|
||||||
|
client := testclient.NewSimpleFake()
|
||||||
fakeWatch := watch.NewFake()
|
fakeWatch := watch.NewFake()
|
||||||
client := &testclient.Fake{}
|
client.PrependWatchReactor("*", testclient.DefaultWatchReactor(fakeWatch, nil))
|
||||||
client.AddWatchReactor("*", testclient.DefaultWatchReactor(fakeWatch, nil))
|
|
||||||
manager := NewJobController(client)
|
manager := NewJobController(client)
|
||||||
manager.podStoreSynced = alwaysReady
|
manager.podStoreSynced = alwaysReady
|
||||||
|
|
||||||
@ -458,9 +458,9 @@ func TestWatchJobs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchPods(t *testing.T) {
|
func TestWatchPods(t *testing.T) {
|
||||||
|
client := testclient.NewSimpleFake()
|
||||||
fakeWatch := watch.NewFake()
|
fakeWatch := watch.NewFake()
|
||||||
client := &testclient.Fake{}
|
client.PrependWatchReactor("*", testclient.DefaultWatchReactor(fakeWatch, nil))
|
||||||
client.AddWatchReactor("*", testclient.DefaultWatchReactor(fakeWatch, nil))
|
|
||||||
manager := NewJobController(client)
|
manager := NewJobController(client)
|
||||||
manager.podStoreSynced = alwaysReady
|
manager.podStoreSynced = alwaysReady
|
||||||
|
|
||||||
|
@ -502,10 +502,7 @@ func TestWatchPods(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdatePods(t *testing.T) {
|
func TestUpdatePods(t *testing.T) {
|
||||||
fakeWatch := watch.NewFake()
|
manager := NewReplicationManager(testclient.NewSimpleFake(), BurstReplicas)
|
||||||
client := &testclient.Fake{}
|
|
||||||
client.AddWatchReactor("*", testclient.DefaultWatchReactor(fakeWatch, nil))
|
|
||||||
manager := NewReplicationManager(client, BurstReplicas)
|
|
||||||
manager.podStoreSynced = alwaysReady
|
manager.podStoreSynced = alwaysReady
|
||||||
|
|
||||||
received := make(chan string)
|
received := make(chan string)
|
||||||
|
@ -26,7 +26,6 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/client/cache"
|
"k8s.io/kubernetes/pkg/client/cache"
|
||||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
"k8s.io/kubernetes/pkg/watch"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestAdmission
|
// TestAdmission
|
||||||
@ -44,10 +43,8 @@ func TestAdmission(t *testing.T) {
|
|||||||
|
|
||||||
store := cache.NewStore(cache.MetaNamespaceKeyFunc)
|
store := cache.NewStore(cache.MetaNamespaceKeyFunc)
|
||||||
store.Add(namespaceObj)
|
store.Add(namespaceObj)
|
||||||
fakeWatch := watch.NewFake()
|
mockClient := testclient.NewSimpleFake()
|
||||||
mockClient := &testclient.Fake{}
|
mockClient.PrependReactor("get", "namespaces", func(action testclient.Action) (bool, runtime.Object, error) {
|
||||||
mockClient.AddWatchReactor("*", testclient.DefaultWatchReactor(fakeWatch, nil))
|
|
||||||
mockClient.AddReactor("get", "namespaces", func(action testclient.Action) (bool, runtime.Object, error) {
|
|
||||||
namespaceLock.RLock()
|
namespaceLock.RLock()
|
||||||
defer namespaceLock.RUnlock()
|
defer namespaceLock.RUnlock()
|
||||||
if getAction, ok := action.(testclient.GetAction); ok && getAction.GetName() == namespaceObj.Name {
|
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)
|
return true, nil, fmt.Errorf("No result for action %v", action)
|
||||||
})
|
})
|
||||||
mockClient.AddReactor("list", "namespaces", func(action testclient.Action) (bool, runtime.Object, error) {
|
mockClient.PrependReactor("list", "namespaces", func(action testclient.Action) (bool, runtime.Object, error) {
|
||||||
namespaceLock.RLock()
|
namespaceLock.RLock()
|
||||||
defer namespaceLock.RUnlock()
|
defer namespaceLock.RUnlock()
|
||||||
return true, &api.NamespaceList{Items: []api.Namespace{*namespaceObj}}, nil
|
return true, &api.NamespaceList{Items: []api.Namespace{*namespaceObj}}, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user