From defdcdfab67fa69b7127f7f12861b41f5e0cff15 Mon Sep 17 00:00:00 2001 From: Shubham Gupta <69793468+shubham-cmyk@users.noreply.github.com> Date: Fri, 10 Nov 2023 21:06:12 +0530 Subject: [PATCH] Add : Mock Client (#699) Signed-off-by: Shubham Gupta --- mocks/client/client_mock.go | 67 +++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 mocks/client/client_mock.go diff --git a/mocks/client/client_mock.go b/mocks/client/client_mock.go new file mode 100644 index 000000000..382378559 --- /dev/null +++ b/mocks/client/client_mock.go @@ -0,0 +1,67 @@ +package client + +import ( + "context" + + "k8s.io/apimachinery/pkg/api/meta" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" +) + +type MockClient struct { + GetFn func(ctx context.Context, key ctrlclient.ObjectKey, obj ctrlclient.Object, opts ...ctrlclient.GetOption) error + ListFn func(ctx context.Context, list ctrlclient.ObjectList, opts ...ctrlclient.ListOption) error + CreateFn func(ctx context.Context, obj ctrlclient.Object, opts ...ctrlclient.CreateOption) error + DeleteFn func(ctx context.Context, obj ctrlclient.Object, opts ...ctrlclient.DeleteOption) error + UpdateFn func(ctx context.Context, obj ctrlclient.Object, opts ...ctrlclient.UpdateOption) error + PatchFn func(ctx context.Context, obj ctrlclient.Object, patch ctrlclient.Patch, opts ...ctrlclient.PatchOption) error + DeleteAllofFn func(ctx context.Context, obj ctrlclient.Object, opts ...ctrlclient.DeleteAllOfOption) error + IsObjectNamespacedFn func(obj runtime.Object) (bool, error) + ctrlclient.StatusClient + ctrlclient.SubResourceClientConstructor +} + +func (m *MockClient) Scheme() *runtime.Scheme { + return nil +} + +func (m *MockClient) RESTMapper() meta.RESTMapper { + return nil +} + +func (m *MockClient) GroupVersionKindFor(obj runtime.Object) (schema.GroupVersionKind, error) { + return schema.GroupVersionKind{}, nil +} + +func (m *MockClient) IsObjectNamespaced(obj runtime.Object) (bool, error) { + return m.IsObjectNamespacedFn(obj) +} + +func (m *MockClient) Get(ctx context.Context, key ctrlclient.ObjectKey, obj ctrlclient.Object, opts ...ctrlclient.GetOption) error { + return m.GetFn(ctx, key, obj, opts...) +} + +func (m *MockClient) List(ctx context.Context, list ctrlclient.ObjectList, opts ...ctrlclient.ListOption) error { + return m.ListFn(ctx, list, opts...) +} + +func (m *MockClient) Create(ctx context.Context, obj ctrlclient.Object, opts ...ctrlclient.CreateOption) error { + return m.CreateFn(ctx, obj, opts...) +} + +func (m *MockClient) Delete(ctx context.Context, obj ctrlclient.Object, opts ...ctrlclient.DeleteOption) error { + return m.DeleteFn(ctx, obj, opts...) +} + +func (m *MockClient) Update(ctx context.Context, obj ctrlclient.Object, opts ...ctrlclient.UpdateOption) error { + return m.UpdateFn(ctx, obj, opts...) +} + +func (m *MockClient) Patch(ctx context.Context, obj ctrlclient.Object, patch ctrlclient.Patch, opts ...ctrlclient.PatchOption) error { + return m.PatchFn(ctx, obj, patch, opts...) +} + +func (m *MockClient) DeleteAllOf(ctx context.Context, obj ctrlclient.Object, opts ...ctrlclient.DeleteAllOfOption) error { + return m.DeleteAllofFn(ctx, obj, opts...) +}