mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +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.AddReactor("*", "*", ObjectReaction(o, api.RESTMapper))
|
||||
|
||||
fakeClient.AddWatchReactor("*", DefaultWatchReactor(watch.NewFake(), nil))
|
||||
|
||||
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
|
||||
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
|
||||
@ -112,11 +112,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) {
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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.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()
|
||||
defer namespaceLock.RUnlock()
|
||||
return true, &api.NamespaceList{Items: []api.Namespace{*namespaceObj}}, nil
|
||||
|
Loading…
Reference in New Issue
Block a user