-
Notifications
You must be signed in to change notification settings - Fork 551
/
fake.go
51 lines (40 loc) · 1.55 KB
/
fake.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package mocks
import (
"context"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/controller/controllertest"
)
// FakeInformers is a fake implementation of Informers.
// Implement a fake informer cache to avoid race condition in informertest.FakeInformers
type FakeInformers struct {
}
func (f *FakeInformers) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
return nil
}
func (f *FakeInformers) WaitForCacheSync(ctx context.Context) bool {
return true
}
func (f *FakeInformers) IndexField(ctx context.Context, obj client.Object, field string, extractValue client.IndexerFunc) error {
return nil
}
func (f *FakeInformers) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error {
return nil
}
func (f *FakeInformers) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, opts ...cache.InformerGetOption) (cache.Informer, error) {
return &controllertest.FakeInformer{}, nil
}
func (f *FakeInformers) Start(ctx context.Context) error {
return nil
}
func (f *FakeInformers) GetInformer(ctx context.Context, obj client.Object, opts ...cache.InformerGetOption) (cache.Informer, error) {
return &controllertest.FakeInformer{}, nil
}
func NewFakeKubeClient() *Client {
c := Client{}
c.OnGetClient().Return(fake.NewClientBuilder().WithRuntimeObjects().Build())
c.OnGetCache().Return(&FakeInformers{})
return &c
}