@@ -31,19 +31,36 @@ import (
3131 "github.com/kcp-dev/api-syncagent/internal/test/diff"
3232 syncagentv1alpha1 "github.com/kcp-dev/api-syncagent/sdk/apis/syncagent/v1alpha1"
3333
34+ corev1 "k8s.io/api/core/v1"
3435 apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
3536 apierrors "k8s.io/apimachinery/pkg/api/errors"
37+ "k8s.io/apimachinery/pkg/api/meta"
3638 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3739 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3840 "k8s.io/apimachinery/pkg/runtime"
41+ utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3942 yamlutil "k8s.io/apimachinery/pkg/util/yaml"
4043 "k8s.io/client-go/tools/record"
4144 ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
4245 fakectrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
4346)
4447
48+ func newFakeClientBuilder () * fakectrlruntimeclient.ClientBuilder {
49+ scheme := runtime .NewScheme ()
50+
51+ utilruntime .Must (metav1 .AddMetaToScheme (scheme ))
52+ utilruntime .Must (corev1 .AddToScheme (scheme ))
53+
54+ mapper := meta .NewDefaultRESTMapper (nil )
55+ for gvk := range scheme .AllKnownTypes () {
56+ mapper .Add (gvk , meta .RESTScopeNamespace )
57+ }
58+
59+ return fakectrlruntimeclient .NewClientBuilder ().WithScheme (scheme ).WithRESTMapper (mapper )
60+ }
61+
4562func buildFakeClient (objs ... * unstructured.Unstructured ) ctrlruntimeclient.Client {
46- builder := fakectrlruntimeclient . NewClientBuilder ()
63+ builder := newFakeClientBuilder ()
4764 for i , obj := range objs {
4865 if obj != nil {
4966 builder .WithObjects (objs [i ])
@@ -54,7 +71,7 @@ func buildFakeClient(objs ...*unstructured.Unstructured) ctrlruntimeclient.Clien
5471}
5572
5673func buildFakeClientWithStatus (objs ... * unstructured.Unstructured ) ctrlruntimeclient.Client {
57- builder := fakectrlruntimeclient . NewClientBuilder ()
74+ builder := newFakeClientBuilder ()
5875 for i , obj := range objs {
5976 if obj != nil {
6077 builder .WithObjects (objs [i ])
0 commit comments