-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathmocks_grpc_test.go
252 lines (233 loc) · 7.4 KB
/
mocks_grpc_test.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package consul
import (
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/serviceconfig"
"sync"
)
// Ensure, that ClientConnMock does implement resolver.ClientConn.
// If this is not the case, regenerate this file with moq.
var _ resolver.ClientConn = &ClientConnMock{}
// ClientConnMock is a mock implementation of resolver.ClientConn.
//
// func TestSomethingThatUsesClientConn(t *testing.T) {
//
// // make and configure a mocked resolver.ClientConn
// mockedClientConn := &ClientConnMock{
// NewAddressFunc: func(addresses []resolver.Address) {
// panic("mock out the NewAddress method")
// },
// NewServiceConfigFunc: func(serviceConfig string) {
// panic("mock out the NewServiceConfig method")
// },
// ParseServiceConfigFunc: func(serviceConfigJSON string) *serviceconfig.ParseResult {
// panic("mock out the ParseServiceConfig method")
// },
// ReportErrorFunc: func(err error) {
// panic("mock out the ReportError method")
// },
// UpdateStateFunc: func(state resolver.State) error {
// panic("mock out the UpdateState method")
// },
// }
//
// // use mockedClientConn in code that requires resolver.ClientConn
// // and then make assertions.
//
// }
type ClientConnMock struct {
// NewAddressFunc mocks the NewAddress method.
NewAddressFunc func(addresses []resolver.Address)
// NewServiceConfigFunc mocks the NewServiceConfig method.
NewServiceConfigFunc func(serviceConfig string)
// ParseServiceConfigFunc mocks the ParseServiceConfig method.
ParseServiceConfigFunc func(serviceConfigJSON string) *serviceconfig.ParseResult
// ReportErrorFunc mocks the ReportError method.
ReportErrorFunc func(err error)
// UpdateStateFunc mocks the UpdateState method.
UpdateStateFunc func(state resolver.State) error
// calls tracks calls to the methods.
calls struct {
// NewAddress holds details about calls to the NewAddress method.
NewAddress []struct {
// Addresses is the addresses argument value.
Addresses []resolver.Address
}
// NewServiceConfig holds details about calls to the NewServiceConfig method.
NewServiceConfig []struct {
// ServiceConfig is the serviceConfig argument value.
ServiceConfig string
}
// ParseServiceConfig holds details about calls to the ParseServiceConfig method.
ParseServiceConfig []struct {
// ServiceConfigJSON is the serviceConfigJSON argument value.
ServiceConfigJSON string
}
// ReportError holds details about calls to the ReportError method.
ReportError []struct {
// Err is the err argument value.
Err error
}
// UpdateState holds details about calls to the UpdateState method.
UpdateState []struct {
// State is the state argument value.
State resolver.State
}
}
lockNewAddress sync.RWMutex
lockNewServiceConfig sync.RWMutex
lockParseServiceConfig sync.RWMutex
lockReportError sync.RWMutex
lockUpdateState sync.RWMutex
}
// NewAddress calls NewAddressFunc.
func (mock *ClientConnMock) NewAddress(addresses []resolver.Address) {
if mock.NewAddressFunc == nil {
panic("ClientConnMock.NewAddressFunc: method is nil but ClientConn.NewAddress was just called")
}
callInfo := struct {
Addresses []resolver.Address
}{
Addresses: addresses,
}
mock.lockNewAddress.Lock()
mock.calls.NewAddress = append(mock.calls.NewAddress, callInfo)
mock.lockNewAddress.Unlock()
mock.NewAddressFunc(addresses)
}
// NewAddressCalls gets all the calls that were made to NewAddress.
// Check the length with:
//
// len(mockedClientConn.NewAddressCalls())
func (mock *ClientConnMock) NewAddressCalls() []struct {
Addresses []resolver.Address
} {
var calls []struct {
Addresses []resolver.Address
}
mock.lockNewAddress.RLock()
calls = mock.calls.NewAddress
mock.lockNewAddress.RUnlock()
return calls
}
// NewServiceConfig calls NewServiceConfigFunc.
func (mock *ClientConnMock) NewServiceConfig(serviceConfig string) {
if mock.NewServiceConfigFunc == nil {
panic("ClientConnMock.NewServiceConfigFunc: method is nil but ClientConn.NewServiceConfig was just called")
}
callInfo := struct {
ServiceConfig string
}{
ServiceConfig: serviceConfig,
}
mock.lockNewServiceConfig.Lock()
mock.calls.NewServiceConfig = append(mock.calls.NewServiceConfig, callInfo)
mock.lockNewServiceConfig.Unlock()
mock.NewServiceConfigFunc(serviceConfig)
}
// NewServiceConfigCalls gets all the calls that were made to NewServiceConfig.
// Check the length with:
//
// len(mockedClientConn.NewServiceConfigCalls())
func (mock *ClientConnMock) NewServiceConfigCalls() []struct {
ServiceConfig string
} {
var calls []struct {
ServiceConfig string
}
mock.lockNewServiceConfig.RLock()
calls = mock.calls.NewServiceConfig
mock.lockNewServiceConfig.RUnlock()
return calls
}
// ParseServiceConfig calls ParseServiceConfigFunc.
func (mock *ClientConnMock) ParseServiceConfig(serviceConfigJSON string) *serviceconfig.ParseResult {
if mock.ParseServiceConfigFunc == nil {
panic("ClientConnMock.ParseServiceConfigFunc: method is nil but ClientConn.ParseServiceConfig was just called")
}
callInfo := struct {
ServiceConfigJSON string
}{
ServiceConfigJSON: serviceConfigJSON,
}
mock.lockParseServiceConfig.Lock()
mock.calls.ParseServiceConfig = append(mock.calls.ParseServiceConfig, callInfo)
mock.lockParseServiceConfig.Unlock()
return mock.ParseServiceConfigFunc(serviceConfigJSON)
}
// ParseServiceConfigCalls gets all the calls that were made to ParseServiceConfig.
// Check the length with:
//
// len(mockedClientConn.ParseServiceConfigCalls())
func (mock *ClientConnMock) ParseServiceConfigCalls() []struct {
ServiceConfigJSON string
} {
var calls []struct {
ServiceConfigJSON string
}
mock.lockParseServiceConfig.RLock()
calls = mock.calls.ParseServiceConfig
mock.lockParseServiceConfig.RUnlock()
return calls
}
// ReportError calls ReportErrorFunc.
func (mock *ClientConnMock) ReportError(err error) {
if mock.ReportErrorFunc == nil {
panic("ClientConnMock.ReportErrorFunc: method is nil but ClientConn.ReportError was just called")
}
callInfo := struct {
Err error
}{
Err: err,
}
mock.lockReportError.Lock()
mock.calls.ReportError = append(mock.calls.ReportError, callInfo)
mock.lockReportError.Unlock()
mock.ReportErrorFunc(err)
}
// ReportErrorCalls gets all the calls that were made to ReportError.
// Check the length with:
//
// len(mockedClientConn.ReportErrorCalls())
func (mock *ClientConnMock) ReportErrorCalls() []struct {
Err error
} {
var calls []struct {
Err error
}
mock.lockReportError.RLock()
calls = mock.calls.ReportError
mock.lockReportError.RUnlock()
return calls
}
// UpdateState calls UpdateStateFunc.
func (mock *ClientConnMock) UpdateState(state resolver.State) error {
if mock.UpdateStateFunc == nil {
panic("ClientConnMock.UpdateStateFunc: method is nil but ClientConn.UpdateState was just called")
}
callInfo := struct {
State resolver.State
}{
State: state,
}
mock.lockUpdateState.Lock()
mock.calls.UpdateState = append(mock.calls.UpdateState, callInfo)
mock.lockUpdateState.Unlock()
return mock.UpdateStateFunc(state)
}
// UpdateStateCalls gets all the calls that were made to UpdateState.
// Check the length with:
//
// len(mockedClientConn.UpdateStateCalls())
func (mock *ClientConnMock) UpdateStateCalls() []struct {
State resolver.State
} {
var calls []struct {
State resolver.State
}
mock.lockUpdateState.RLock()
calls = mock.calls.UpdateState
mock.lockUpdateState.RUnlock()
return calls
}