forked from TheThingsArchive/ttn
/
mocks.go
373 lines (338 loc) · 10.4 KB
/
mocks.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
// Copyright © 2016 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
// Package mocks offers dedicated mocking interface / structures for testing
package mocks
import (
"github.com/LoRaWanSoFa/ttn/core"
"github.com/LoRaWanSoFa/ttn/core/dutycycle"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
// NOTE: All the code below could be generated
// AppClient mocks the core.AppClient interface
type AppClient struct {
Failures map[string]error
InHandleData struct {
Ctx context.Context
Req *core.DataAppReq
Opts []grpc.CallOption
}
OutHandleData struct {
Res *core.DataAppRes
}
InHandleJoin struct {
Ctx context.Context
Req *core.JoinAppReq
Opts []grpc.CallOption
}
OutHandleJoin struct {
Res *core.JoinAppRes
}
}
// NewAppClient creates a new mock AppClient
func NewAppClient() *AppClient {
return &AppClient{
Failures: make(map[string]error),
}
}
// HandleJoin implements the core.AppClient interface
func (m *AppClient) HandleJoin(ctx context.Context, in *core.JoinAppReq, opts ...grpc.CallOption) (*core.JoinAppRes, error) {
m.InHandleJoin.Ctx = ctx
m.InHandleJoin.Req = in
m.InHandleJoin.Opts = opts
return m.OutHandleJoin.Res, m.Failures["HandleJoin"]
}
// HandleData implements the core.AppClient interface
func (m *AppClient) HandleData(ctx context.Context, in *core.DataAppReq, opts ...grpc.CallOption) (*core.DataAppRes, error) {
m.InHandleData.Ctx = ctx
m.InHandleData.Req = in
m.InHandleData.Opts = opts
return m.OutHandleData.Res, m.Failures["HandleData"]
}
// HandlerClient mocks the core.HandlerClient interface
type HandlerClient struct {
Failures map[string]error
InHandleJoin struct {
Ctx context.Context
Req *core.JoinHandlerReq
Opts []grpc.CallOption
}
OutHandleJoin struct {
Res *core.JoinHandlerRes
}
InHandleDataUp struct {
Ctx context.Context
Req *core.DataUpHandlerReq
Opts []grpc.CallOption
}
OutHandleDataUp struct {
Res *core.DataUpHandlerRes
}
InHandleDataDown struct {
Ctx context.Context
Req *core.DataDownHandlerReq
Opts []grpc.CallOption
}
OutHandleDataDown struct {
Res *core.DataDownHandlerRes
}
}
// NewHandlerClient creates a new mock HandlerClient
func NewHandlerClient() *HandlerClient {
return &HandlerClient{
Failures: make(map[string]error),
}
}
// HandleJoin implements the core.HandlerClient interface
func (m *HandlerClient) HandleJoin(ctx context.Context, in *core.JoinHandlerReq, opts ...grpc.CallOption) (*core.JoinHandlerRes, error) {
m.InHandleJoin.Ctx = ctx
m.InHandleJoin.Req = in
m.InHandleJoin.Opts = opts
return m.OutHandleJoin.Res, m.Failures["HandleJoin"]
}
// HandleDataUp implements the core.HandlerClient interface
func (m *HandlerClient) HandleDataUp(ctx context.Context, in *core.DataUpHandlerReq, opts ...grpc.CallOption) (*core.DataUpHandlerRes, error) {
m.InHandleDataUp.Ctx = ctx
m.InHandleDataUp.Req = in
m.InHandleDataUp.Opts = opts
return m.OutHandleDataUp.Res, m.Failures["HandleDataUp"]
}
// HandleDataDown implements the core.HandlerClient interface
func (m *HandlerClient) HandleDataDown(ctx context.Context, in *core.DataDownHandlerReq, opts ...grpc.CallOption) (*core.DataDownHandlerRes, error) {
m.InHandleDataDown.Ctx = ctx
m.InHandleDataDown.Req = in
m.InHandleDataDown.Opts = opts
return m.OutHandleDataDown.Res, m.Failures["HandleDataDown"]
}
// AuthBrokerClient mocks the core.AuthBrokerClient interface
type AuthBrokerClient struct {
Failures map[string]error
InHandleData struct {
Ctx context.Context
Req *core.DataBrokerReq
Opts []grpc.CallOption
}
OutHandleData struct {
Res *core.DataBrokerRes
}
InHandleJoin struct {
Ctx context.Context
Req *core.JoinBrokerReq
Opts []grpc.CallOption
}
OutHandleJoin struct {
Res *core.JoinBrokerRes
}
InUpsertABP struct {
Ctx context.Context
Req *core.UpsertABPBrokerReq
Opts []grpc.CallOption
}
OutUpsertABP struct {
Res *core.UpsertABPBrokerRes
}
InValidateOTAA struct {
Ctx context.Context
Req *core.ValidateOTAABrokerReq
Opts []grpc.CallOption
}
OutValidateOTAA struct {
Res *core.ValidateOTAABrokerRes
}
InValidateToken struct {
Ctx context.Context
Req *core.ValidateTokenBrokerReq
Opts []grpc.CallOption
}
OutValidateToken struct {
Res *core.ValidateTokenBrokerRes
}
}
// NewAuthBrokerClient creates a new mock AuthBrokerClient
func NewAuthBrokerClient() *AuthBrokerClient {
return &AuthBrokerClient{
Failures: make(map[string]error),
}
}
// HandleData implements the core.Broker interface
func (m *AuthBrokerClient) HandleData(ctx context.Context, in *core.DataBrokerReq, opts ...grpc.CallOption) (*core.DataBrokerRes, error) {
m.InHandleData.Ctx = ctx
m.InHandleData.Req = in
m.InHandleData.Opts = opts
return m.OutHandleData.Res, m.Failures["HandleData"]
}
// HandleJoin implements the core.Broker interface
func (m *AuthBrokerClient) HandleJoin(ctx context.Context, in *core.JoinBrokerReq, opts ...grpc.CallOption) (*core.JoinBrokerRes, error) {
m.InHandleJoin.Ctx = ctx
m.InHandleJoin.Req = in
m.InHandleJoin.Opts = opts
return m.OutHandleJoin.Res, m.Failures["HandleJoin"]
}
// UpsertABP implements the core.Broker interface
func (m *AuthBrokerClient) UpsertABP(ctx context.Context, in *core.UpsertABPBrokerReq, opts ...grpc.CallOption) (*core.UpsertABPBrokerRes, error) {
m.InUpsertABP.Ctx = ctx
m.InUpsertABP.Req = in
m.InUpsertABP.Opts = opts
return m.OutUpsertABP.Res, m.Failures["UpsertABP"]
}
// ValidateOTAA implements the core.Broker interface
func (m *AuthBrokerClient) ValidateOTAA(ctx context.Context, in *core.ValidateOTAABrokerReq, opts ...grpc.CallOption) (*core.ValidateOTAABrokerRes, error) {
m.InValidateOTAA.Ctx = ctx
m.InValidateOTAA.Req = in
m.InValidateOTAA.Opts = opts
return m.OutValidateOTAA.Res, m.Failures["ValidateOTAA"]
}
// DeleteDevice implements the core.Broker interface
func (m *AuthBrokerClient) DeleteDevice(ctx context.Context, in *core.DeleteDeviceBrokerReq, opts ...grpc.CallOption) (*core.DeleteDeviceBrokerRes, error) {
return new(core.DeleteDeviceBrokerRes), nil
}
// ValidateToken implements the core.Broker interface
func (m *AuthBrokerClient) ValidateToken(ctx context.Context, in *core.ValidateTokenBrokerReq, opts ...grpc.CallOption) (*core.ValidateTokenBrokerRes, error) {
m.InValidateToken.Ctx = ctx
m.InValidateToken.Req = in
m.InValidateToken.Opts = opts
return m.OutValidateToken.Res, m.Failures["ValidateToken"]
}
// RouterServer mocks the core.RouterServer interface
type RouterServer struct {
Failures map[string]error
InHandleData struct {
Ctx context.Context
Req *core.DataRouterReq
}
OutHandleData struct {
Res *core.DataRouterRes
}
InHandleStats struct {
Ctx context.Context
Req *core.StatsReq
}
OutHandleStats struct {
Res *core.StatsRes
}
InHandleJoin struct {
Ctx context.Context
Req *core.JoinRouterReq
}
OutHandleJoin struct {
Res *core.JoinRouterRes
}
}
// NewRouterServer creates a new mock RouterServer
func NewRouterServer() *RouterServer {
return &RouterServer{
Failures: make(map[string]error),
}
}
// HandleData implements the core.RouterServer interface
func (m *RouterServer) HandleData(ctx context.Context, in *core.DataRouterReq) (*core.DataRouterRes, error) {
m.InHandleData.Ctx = ctx
m.InHandleData.Req = in
return m.OutHandleData.Res, m.Failures["HandleData"]
}
// HandleStats implements the core.RouterServer interface
func (m *RouterServer) HandleStats(ctx context.Context, in *core.StatsReq) (*core.StatsRes, error) {
m.InHandleStats.Ctx = ctx
m.InHandleStats.Req = in
return m.OutHandleStats.Res, m.Failures["HandleStats"]
}
// HandleJoin implements the core.RouterServer interface
func (m *RouterServer) HandleJoin(ctx context.Context, in *core.JoinRouterReq) (*core.JoinRouterRes, error) {
m.InHandleJoin.Ctx = ctx
m.InHandleJoin.Req = in
return m.OutHandleJoin.Res, m.Failures["HandleJoin"]
}
// DutyManager mocks the dutycycle.DutyManager interface
type DutyManager struct {
Failures map[string]error
InUpdate struct {
ID []byte
Freq float32
Size uint32
Datr string
Codr string
}
InLookup struct {
ID []byte
}
OutLookup struct {
Cycles dutycycle.Cycles
}
InClose struct {
Called bool
}
}
// NewDutyManager creates a new mock DutyManager
func NewDutyManager() *DutyManager {
return &DutyManager{
Failures: make(map[string]error),
}
}
// Update implements the dutycycle.DutyManager interface
func (m *DutyManager) Update(id []byte, freq float32, size uint32, datr string, codr string) error {
m.InUpdate.ID = id
m.InUpdate.Freq = freq
m.InUpdate.Size = size
m.InUpdate.Datr = datr
m.InUpdate.Codr = codr
return m.Failures["Update"]
}
// Lookup implements the dutycycle.DutyManager interface
func (m *DutyManager) Lookup(id []byte) (dutycycle.Cycles, error) {
m.InLookup.ID = id
return m.OutLookup.Cycles, m.Failures["Lookup"]
}
// Close implements the dutycycle.DutyManager interface
func (m *DutyManager) Close() error {
m.InClose.Called = true
return m.Failures["Close"]
}
// HandlerServer mocks the core.HandlerServer interface
type HandlerServer struct {
Failures map[string]error
InHandleDataUp struct {
Ctx context.Context
Req *core.DataUpHandlerReq
}
OutHandleDataUp struct {
Res *core.DataUpHandlerRes
}
InHandleDataDown struct {
Ctx context.Context
Req *core.DataDownHandlerReq
}
OutHandleDataDown struct {
Res *core.DataDownHandlerRes
}
InHandleJoin struct {
Ctx context.Context
Req *core.JoinHandlerReq
}
OutHandleJoin struct {
Res *core.JoinHandlerRes
}
}
// NewHandlerServer creates a new mock HandlerServer
func NewHandlerServer() *HandlerServer {
return &HandlerServer{
Failures: make(map[string]error),
}
}
// HandleDataUp implements the core.HandlerServer interface
func (m *HandlerServer) HandleDataUp(ctx context.Context, in *core.DataUpHandlerReq) (*core.DataUpHandlerRes, error) {
m.InHandleDataUp.Ctx = ctx
m.InHandleDataUp.Req = in
return m.OutHandleDataUp.Res, m.Failures["HandleDataUp"]
}
// HandleDataDown implements the core.HandlerServer interface
func (m *HandlerServer) HandleDataDown(ctx context.Context, in *core.DataDownHandlerReq) (*core.DataDownHandlerRes, error) {
m.InHandleDataDown.Ctx = ctx
m.InHandleDataDown.Req = in
return m.OutHandleDataDown.Res, m.Failures["HandleDataDown"]
}
// HandleJoin implements the core.HandlerServer interface
func (m *HandlerServer) HandleJoin(ctx context.Context, in *core.JoinHandlerReq) (*core.JoinHandlerRes, error) {
m.InHandleJoin.Ctx = ctx
m.InHandleJoin.Req = in
return m.OutHandleJoin.Res, m.Failures["HandleJoin"]
}