-
Notifications
You must be signed in to change notification settings - Fork 40
/
client.go
99 lines (76 loc) · 2.37 KB
/
client.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package testutil
import (
"context"
"github.com/stretchr/testify/mock"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
// Client is a mock for the controller-runtime dynamic client interface.
type Client struct {
mock.Mock
StatusMock *StatusClient
}
var _ client.Client = &Client{}
func NewClient() *Client {
return &Client{
StatusMock: &StatusClient{},
}
}
// StatusClient interface
func (c *Client) Status() client.StatusWriter {
return c.StatusMock
}
// Reader interface
func (c *Client) Get(ctx context.Context, key types.NamespacedName, obj client.Object) error {
args := c.Called(ctx, key, obj)
return args.Error(0)
}
func (c *Client) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error {
args := c.Called(ctx, list, opts)
return args.Error(0)
}
// Writer interface
func (c *Client) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error {
args := c.Called(ctx, obj, opts)
return args.Error(0)
}
func (c *Client) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error {
args := c.Called(ctx, obj, opts)
return args.Error(0)
}
func (c *Client) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error {
args := c.Called(ctx, obj, opts)
return args.Error(0)
}
func (c *Client) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error {
args := c.Called(ctx, obj, patch, opts)
return args.Error(0)
}
func (c *Client) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error {
args := c.Called(ctx, obj, opts)
return args.Error(0)
}
func (c *Client) Scheme() *runtime.Scheme {
args := c.Called()
return args.Get(0).(*runtime.Scheme)
}
func (c *Client) RESTMapper() meta.RESTMapper {
args := c.Called()
return args.Get(0).(meta.RESTMapper)
}
type StatusClient struct {
mock.Mock
}
var _ client.StatusWriter = &StatusClient{}
func (c *StatusClient) Update(
ctx context.Context, obj client.Object, opts ...client.UpdateOption) error {
args := c.Called(ctx, obj, opts)
return args.Error(0)
}
func (c *StatusClient) Patch(
ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error {
args := c.Called(ctx, obj, patch, opts)
return args.Error(0)
}