Merge pull request #12293 from deads2k/testclient-specific-reaction
Auto commit by PR queue bot
This commit is contained in:
@@ -36,15 +36,14 @@ func TestAdmissionDeny(t *testing.T) {
|
||||
}
|
||||
|
||||
func testAdmission(t *testing.T, pod *api.Pod, shouldAccept bool) {
|
||||
mockClient := &testclient.Fake{
|
||||
ReactFn: func(action testclient.Action) (runtime.Object, error) {
|
||||
if action.Matches("get", "pods") && action.(testclient.GetAction).GetName() == pod.Name {
|
||||
return pod, nil
|
||||
}
|
||||
t.Errorf("Unexpected API call: %#v", action)
|
||||
return nil, nil
|
||||
},
|
||||
}
|
||||
mockClient := &testclient.Fake{}
|
||||
mockClient.AddReactor("get", "pods", func(action testclient.Action) (bool, runtime.Object, error) {
|
||||
if action.(testclient.GetAction).GetName() == pod.Name {
|
||||
return true, pod, nil
|
||||
}
|
||||
t.Errorf("Unexpected API call: %#v", action)
|
||||
return true, nil, nil
|
||||
})
|
||||
handler := &denyExecOnPrivileged{
|
||||
client: mockClient,
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/cache"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
// TestAdmission verifies a namespace is created on create requests for namespace managed resources
|
||||
@@ -107,7 +108,9 @@ func TestIgnoreAdmission(t *testing.T) {
|
||||
func TestAdmissionNamespaceExistsUnknownToHandler(t *testing.T) {
|
||||
namespace := "test"
|
||||
mockClient := &testclient.Fake{}
|
||||
mockClient.SetErr(errors.NewAlreadyExists("namespaces", namespace))
|
||||
mockClient.AddReactor("create", "namespaces", func(action testclient.Action) (bool, runtime.Object, error) {
|
||||
return true, nil, errors.NewAlreadyExists("namespaces", namespace)
|
||||
})
|
||||
|
||||
store := cache.NewStore(cache.MetaNamespaceKeyFunc)
|
||||
handler := &provision{
|
||||
|
||||
@@ -40,24 +40,21 @@ func TestAdmission(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
reactFunc := func(action testclient.Action) (runtime.Object, error) {
|
||||
switch {
|
||||
case action.Matches("get", "namespaces"):
|
||||
if getAction, ok := action.(testclient.GetAction); ok && getAction.GetName() == namespaceObj.Name {
|
||||
return namespaceObj, nil
|
||||
}
|
||||
case action.Matches("list", "namespaces"):
|
||||
return &api.NamespaceList{Items: []api.Namespace{*namespaceObj}}, nil
|
||||
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("No result for action %v", action)
|
||||
}
|
||||
|
||||
store := cache.NewStore(cache.MetaNamespaceKeyFunc)
|
||||
store.Add(namespaceObj)
|
||||
fakeWatch := watch.NewFake()
|
||||
mockClient := &testclient.Fake{Watch: fakeWatch, ReactFn: reactFunc}
|
||||
mockClient := &testclient.Fake{}
|
||||
mockClient.AddWatchReactor("*", testclient.DefaultWatchReactor(fakeWatch, nil))
|
||||
mockClient.AddReactor("get", "namespaces", func(action testclient.Action) (bool, runtime.Object, error) {
|
||||
if getAction, ok := action.(testclient.GetAction); ok && getAction.GetName() == namespaceObj.Name {
|
||||
return true, namespaceObj, nil
|
||||
}
|
||||
return true, nil, fmt.Errorf("No result for action %v", action)
|
||||
})
|
||||
mockClient.AddReactor("list", "namespaces", func(action testclient.Action) (bool, runtime.Object, error) {
|
||||
return true, &api.NamespaceList{Items: []api.Namespace{*namespaceObj}}, nil
|
||||
})
|
||||
|
||||
lfhandler := NewLifecycle(mockClient).(*lifecycle)
|
||||
lfhandler.store = store
|
||||
handler := admission.NewChainHandler(lfhandler)
|
||||
|
||||
Reference in New Issue
Block a user