Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add : Mock Client #699

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions mocks/client/client_mock.go
Original file line number Diff line number Diff line change
@@ -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...)
}
Loading