Skip to content

Commit 736e556

Browse files
committed
Align fake client-go clients with the main interface
"Real" clients use objectWithMeta to enforce support for meta.Object; strictly speaking, fakes don't need this, but it's best to align them with the real clients to ensure that fakes don't end up allowing types that can't be used with the real clients. Signed-off-by: Stephen Kitt <[email protected]>
1 parent be03bcf commit 736e556

File tree

1 file changed

+10
-10
lines changed
  • staging/src/k8s.io/client-go/gentype

1 file changed

+10
-10
lines changed

staging/src/k8s.io/client-go/gentype/fake.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
)
3333

3434
// FakeClient represents a fake client
35-
type FakeClient[T runtime.Object] struct {
35+
type FakeClient[T objectWithMeta] struct {
3636
*testing.Fake
3737
ns string
3838
resource schema.GroupVersionResource
@@ -41,47 +41,47 @@ type FakeClient[T runtime.Object] struct {
4141
}
4242

4343
// FakeClientWithList represents a fake client with support for lists.
44-
type FakeClientWithList[T runtime.Object, L runtime.Object] struct {
44+
type FakeClientWithList[T objectWithMeta, L runtime.Object] struct {
4545
*FakeClient[T]
4646
alsoFakeLister[T, L]
4747
}
4848

4949
// FakeClientWithApply represents a fake client with support for apply declarative configurations.
50-
type FakeClientWithApply[T runtime.Object, C namedObject] struct {
50+
type FakeClientWithApply[T objectWithMeta, C namedObject] struct {
5151
*FakeClient[T]
5252
alsoFakeApplier[T, C]
5353
}
5454

5555
// FakeClientWithListAndApply represents a fake client with support for lists and apply declarative configurations.
56-
type FakeClientWithListAndApply[T runtime.Object, L runtime.Object, C namedObject] struct {
56+
type FakeClientWithListAndApply[T objectWithMeta, L runtime.Object, C namedObject] struct {
5757
*FakeClient[T]
5858
alsoFakeLister[T, L]
5959
alsoFakeApplier[T, C]
6060
}
6161

6262
// Helper types for composition
63-
type alsoFakeLister[T runtime.Object, L runtime.Object] struct {
63+
type alsoFakeLister[T objectWithMeta, L runtime.Object] struct {
6464
client *FakeClient[T]
6565
newList func() L
6666
copyListMeta func(L, L)
6767
getItems func(L) []T
6868
setItems func(L, []T)
6969
}
7070

71-
type alsoFakeApplier[T runtime.Object, C namedObject] struct {
71+
type alsoFakeApplier[T objectWithMeta, C namedObject] struct {
7272
client *FakeClient[T]
7373
}
7474

7575
// NewFakeClient constructs a fake client, namespaced or not, with no support for lists or apply.
7676
// Non-namespaced clients are constructed by passing an empty namespace ("").
77-
func NewFakeClient[T runtime.Object](
77+
func NewFakeClient[T objectWithMeta](
7878
fake *testing.Fake, namespace string, resource schema.GroupVersionResource, kind schema.GroupVersionKind, emptyObjectCreator func() T,
7979
) *FakeClient[T] {
8080
return &FakeClient[T]{fake, namespace, resource, kind, emptyObjectCreator}
8181
}
8282

8383
// NewFakeClientWithList constructs a namespaced client with support for lists.
84-
func NewFakeClientWithList[T runtime.Object, L runtime.Object](
84+
func NewFakeClientWithList[T objectWithMeta, L runtime.Object](
8585
fake *testing.Fake, namespace string, resource schema.GroupVersionResource, kind schema.GroupVersionKind, emptyObjectCreator func() T,
8686
emptyListCreator func() L, listMetaCopier func(L, L), itemGetter func(L) []T, itemSetter func(L, []T),
8787
) *FakeClientWithList[T, L] {
@@ -93,7 +93,7 @@ func NewFakeClientWithList[T runtime.Object, L runtime.Object](
9393
}
9494

9595
// NewFakeClientWithApply constructs a namespaced client with support for apply declarative configurations.
96-
func NewFakeClientWithApply[T runtime.Object, C namedObject](
96+
func NewFakeClientWithApply[T objectWithMeta, C namedObject](
9797
fake *testing.Fake, namespace string, resource schema.GroupVersionResource, kind schema.GroupVersionKind, emptyObjectCreator func() T,
9898
) *FakeClientWithApply[T, C] {
9999
fakeClient := NewFakeClient[T](fake, namespace, resource, kind, emptyObjectCreator)
@@ -104,7 +104,7 @@ func NewFakeClientWithApply[T runtime.Object, C namedObject](
104104
}
105105

106106
// NewFakeClientWithListAndApply constructs a client with support for lists and applying declarative configurations.
107-
func NewFakeClientWithListAndApply[T runtime.Object, L runtime.Object, C namedObject](
107+
func NewFakeClientWithListAndApply[T objectWithMeta, L runtime.Object, C namedObject](
108108
fake *testing.Fake, namespace string, resource schema.GroupVersionResource, kind schema.GroupVersionKind, emptyObjectCreator func() T,
109109
emptyListCreator func() L, listMetaCopier func(L, L), itemGetter func(L) []T, itemSetter func(L, []T),
110110
) *FakeClientWithListAndApply[T, L, C] {

0 commit comments

Comments
 (0)