Skip to content

Commit bf25854

Browse files
committed
Remove dependency on fake client
1 parent 6063435 commit bf25854

File tree

1 file changed

+85
-4
lines changed

1 file changed

+85
-4
lines changed

pkg/client/interceptor/intercept_test.go

+85-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package interceptor
33
import (
44
"context"
55

6-
"sigs.k8s.io/controller-runtime/pkg/client/fake"
6+
"k8s.io/apimachinery/pkg/api/meta"
7+
"k8s.io/apimachinery/pkg/runtime"
8+
"k8s.io/apimachinery/pkg/runtime/schema"
79

810
. "github.com/onsi/ginkgo/v2"
911
. "github.com/onsi/gomega"
@@ -13,7 +15,7 @@ import (
1315
)
1416

1517
var _ = Describe("NewClient", func() {
16-
wrappedClient := fake.NewClientBuilder().Build()
18+
wrappedClient := dummyClient{}
1719
ctx := context.Background()
1820
It("should call the provided Get function", func() {
1921
var called bool
@@ -252,8 +254,7 @@ var _ = Describe("NewClient", func() {
252254
})
253255

254256
var _ = Describe("NewSubResourceClient", func() {
255-
wrappedClient := fake.NewClientBuilder().Build()
256-
srClient := wrappedClient.SubResource("test")
257+
srClient := dummySubResourceClient{}
257258
ctx := context.Background()
258259
It("should call the provided Get function", func() {
259260
var called bool
@@ -348,3 +349,83 @@ var _ = Describe("NewSubResourceClient", func() {
348349
Expect(called).To(BeTrue())
349350
})
350351
})
352+
353+
type dummyClient struct{}
354+
355+
var _ client.WithWatch = &dummyClient{}
356+
357+
func (d dummyClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
358+
return nil
359+
}
360+
361+
func (d dummyClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error {
362+
return nil
363+
}
364+
365+
func (d dummyClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error {
366+
return nil
367+
}
368+
369+
func (d dummyClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error {
370+
return nil
371+
}
372+
373+
func (d dummyClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error {
374+
return nil
375+
}
376+
377+
func (d dummyClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error {
378+
return nil
379+
}
380+
381+
func (d dummyClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error {
382+
return nil
383+
}
384+
385+
func (d dummyClient) Status() client.SubResourceWriter {
386+
return d.SubResource("status")
387+
}
388+
389+
func (d dummyClient) SubResource(subResource string) client.SubResourceClient {
390+
return nil
391+
}
392+
393+
func (d dummyClient) Scheme() *runtime.Scheme {
394+
return nil
395+
}
396+
397+
func (d dummyClient) RESTMapper() meta.RESTMapper {
398+
return nil
399+
}
400+
401+
func (d dummyClient) GroupVersionKindFor(obj runtime.Object) (schema.GroupVersionKind, error) {
402+
return schema.GroupVersionKind{}, nil
403+
}
404+
405+
func (d dummyClient) IsObjectNamespaced(obj runtime.Object) (bool, error) {
406+
return false, nil
407+
}
408+
409+
func (d dummyClient) Watch(ctx context.Context, obj client.ObjectList, opts ...client.ListOption) (watch.Interface, error) {
410+
return nil, nil
411+
}
412+
413+
type dummySubResourceClient struct{}
414+
415+
var _ client.SubResourceClient = &dummySubResourceClient{}
416+
417+
func (d dummySubResourceClient) Get(ctx context.Context, obj client.Object, subResource client.Object, opts ...client.SubResourceGetOption) error {
418+
return nil
419+
}
420+
421+
func (d dummySubResourceClient) Create(ctx context.Context, obj client.Object, subResource client.Object, opts ...client.SubResourceCreateOption) error {
422+
return nil
423+
}
424+
425+
func (d dummySubResourceClient) Update(ctx context.Context, obj client.Object, opts ...client.SubResourceUpdateOption) error {
426+
return nil
427+
}
428+
429+
func (d dummySubResourceClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.SubResourcePatchOption) error {
430+
return nil
431+
}

0 commit comments

Comments
 (0)