-
Notifications
You must be signed in to change notification settings - Fork 2
/
mock_fs_test.go
490 lines (425 loc) · 14.9 KB
/
mock_fs_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
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
// Code generated by go-mockgen 0.1.0; DO NOT EDIT.
package config
import "sync"
// MockFileSystem is a mock implementation of the FileSystem interface (from
// the package github.com/go-nacelle/config) used for unit testing.
type MockFileSystem struct {
// ExistsFunc is an instance of a mock function object controlling the
// behavior of the method Exists.
ExistsFunc *FileSystemExistsFunc
// GlobFunc is an instance of a mock function object controlling the
// behavior of the method Glob.
GlobFunc *FileSystemGlobFunc
// ListFilesFunc is an instance of a mock function object controlling
// the behavior of the method ListFiles.
ListFilesFunc *FileSystemListFilesFunc
// ReadFileFunc is an instance of a mock function object controlling the
// behavior of the method ReadFile.
ReadFileFunc *FileSystemReadFileFunc
}
// NewMockFileSystem creates a new mock of the FileSystem interface. All
// methods return zero values for all results, unless overwritten.
func NewMockFileSystem() *MockFileSystem {
return &MockFileSystem{
ExistsFunc: &FileSystemExistsFunc{
defaultHook: func(string) (bool, error) {
return false, nil
},
},
GlobFunc: &FileSystemGlobFunc{
defaultHook: func(string) ([]string, error) {
return nil, nil
},
},
ListFilesFunc: &FileSystemListFilesFunc{
defaultHook: func(string) ([]string, error) {
return nil, nil
},
},
ReadFileFunc: &FileSystemReadFileFunc{
defaultHook: func(string) ([]byte, error) {
return nil, nil
},
},
}
}
// NewMockFileSystemFrom creates a new mock of the MockFileSystem interface.
// All methods delegate to the given implementation, unless overwritten.
func NewMockFileSystemFrom(i FileSystem) *MockFileSystem {
return &MockFileSystem{
ExistsFunc: &FileSystemExistsFunc{
defaultHook: i.Exists,
},
GlobFunc: &FileSystemGlobFunc{
defaultHook: i.Glob,
},
ListFilesFunc: &FileSystemListFilesFunc{
defaultHook: i.ListFiles,
},
ReadFileFunc: &FileSystemReadFileFunc{
defaultHook: i.ReadFile,
},
}
}
// FileSystemExistsFunc describes the behavior when the Exists method of the
// parent MockFileSystem instance is invoked.
type FileSystemExistsFunc struct {
defaultHook func(string) (bool, error)
hooks []func(string) (bool, error)
history []FileSystemExistsFuncCall
mutex sync.Mutex
}
// Exists delegates to the next hook function in the queue and stores the
// parameter and result values of this invocation.
func (m *MockFileSystem) Exists(v0 string) (bool, error) {
r0, r1 := m.ExistsFunc.nextHook()(v0)
m.ExistsFunc.appendCall(FileSystemExistsFuncCall{v0, r0, r1})
return r0, r1
}
// SetDefaultHook sets function that is called when the Exists method of the
// parent MockFileSystem instance is invoked and the hook queue is empty.
func (f *FileSystemExistsFunc) SetDefaultHook(hook func(string) (bool, error)) {
f.defaultHook = hook
}
// PushHook adds a function to the end of hook queue. Each invocation of the
// Exists method of the parent MockFileSystem instance invokes the hook at
// the front of the queue and discards it. After the queue is empty, the
// default hook function is invoked for any future action.
func (f *FileSystemExistsFunc) PushHook(hook func(string) (bool, error)) {
f.mutex.Lock()
f.hooks = append(f.hooks, hook)
f.mutex.Unlock()
}
// SetDefaultReturn calls SetDefaultDefaultHook with a function that returns
// the given values.
func (f *FileSystemExistsFunc) SetDefaultReturn(r0 bool, r1 error) {
f.SetDefaultHook(func(string) (bool, error) {
return r0, r1
})
}
// PushReturn calls PushDefaultHook with a function that returns the given
// values.
func (f *FileSystemExistsFunc) PushReturn(r0 bool, r1 error) {
f.PushHook(func(string) (bool, error) {
return r0, r1
})
}
func (f *FileSystemExistsFunc) nextHook() func(string) (bool, error) {
f.mutex.Lock()
defer f.mutex.Unlock()
if len(f.hooks) == 0 {
return f.defaultHook
}
hook := f.hooks[0]
f.hooks = f.hooks[1:]
return hook
}
func (f *FileSystemExistsFunc) appendCall(r0 FileSystemExistsFuncCall) {
f.mutex.Lock()
f.history = append(f.history, r0)
f.mutex.Unlock()
}
// History returns a sequence of FileSystemExistsFuncCall objects describing
// the invocations of this function.
func (f *FileSystemExistsFunc) History() []FileSystemExistsFuncCall {
f.mutex.Lock()
history := make([]FileSystemExistsFuncCall, len(f.history))
copy(history, f.history)
f.mutex.Unlock()
return history
}
// FileSystemExistsFuncCall is an object that describes an invocation of
// method Exists on an instance of MockFileSystem.
type FileSystemExistsFuncCall struct {
// Arg0 is the value of the 1st argument passed to this method
// invocation.
Arg0 string
// Result0 is the value of the 1st result returned from this method
// invocation.
Result0 bool
// Result1 is the value of the 2nd result returned from this method
// invocation.
Result1 error
}
// Args returns an interface slice containing the arguments of this
// invocation.
func (c FileSystemExistsFuncCall) Args() []interface{} {
return []interface{}{c.Arg0}
}
// Results returns an interface slice containing the results of this
// invocation.
func (c FileSystemExistsFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1}
}
// FileSystemGlobFunc describes the behavior when the Glob method of the
// parent MockFileSystem instance is invoked.
type FileSystemGlobFunc struct {
defaultHook func(string) ([]string, error)
hooks []func(string) ([]string, error)
history []FileSystemGlobFuncCall
mutex sync.Mutex
}
// Glob delegates to the next hook function in the queue and stores the
// parameter and result values of this invocation.
func (m *MockFileSystem) Glob(v0 string) ([]string, error) {
r0, r1 := m.GlobFunc.nextHook()(v0)
m.GlobFunc.appendCall(FileSystemGlobFuncCall{v0, r0, r1})
return r0, r1
}
// SetDefaultHook sets function that is called when the Glob method of the
// parent MockFileSystem instance is invoked and the hook queue is empty.
func (f *FileSystemGlobFunc) SetDefaultHook(hook func(string) ([]string, error)) {
f.defaultHook = hook
}
// PushHook adds a function to the end of hook queue. Each invocation of the
// Glob method of the parent MockFileSystem instance invokes the hook at the
// front of the queue and discards it. After the queue is empty, the default
// hook function is invoked for any future action.
func (f *FileSystemGlobFunc) PushHook(hook func(string) ([]string, error)) {
f.mutex.Lock()
f.hooks = append(f.hooks, hook)
f.mutex.Unlock()
}
// SetDefaultReturn calls SetDefaultDefaultHook with a function that returns
// the given values.
func (f *FileSystemGlobFunc) SetDefaultReturn(r0 []string, r1 error) {
f.SetDefaultHook(func(string) ([]string, error) {
return r0, r1
})
}
// PushReturn calls PushDefaultHook with a function that returns the given
// values.
func (f *FileSystemGlobFunc) PushReturn(r0 []string, r1 error) {
f.PushHook(func(string) ([]string, error) {
return r0, r1
})
}
func (f *FileSystemGlobFunc) nextHook() func(string) ([]string, error) {
f.mutex.Lock()
defer f.mutex.Unlock()
if len(f.hooks) == 0 {
return f.defaultHook
}
hook := f.hooks[0]
f.hooks = f.hooks[1:]
return hook
}
func (f *FileSystemGlobFunc) appendCall(r0 FileSystemGlobFuncCall) {
f.mutex.Lock()
f.history = append(f.history, r0)
f.mutex.Unlock()
}
// History returns a sequence of FileSystemGlobFuncCall objects describing
// the invocations of this function.
func (f *FileSystemGlobFunc) History() []FileSystemGlobFuncCall {
f.mutex.Lock()
history := make([]FileSystemGlobFuncCall, len(f.history))
copy(history, f.history)
f.mutex.Unlock()
return history
}
// FileSystemGlobFuncCall is an object that describes an invocation of
// method Glob on an instance of MockFileSystem.
type FileSystemGlobFuncCall struct {
// Arg0 is the value of the 1st argument passed to this method
// invocation.
Arg0 string
// Result0 is the value of the 1st result returned from this method
// invocation.
Result0 []string
// Result1 is the value of the 2nd result returned from this method
// invocation.
Result1 error
}
// Args returns an interface slice containing the arguments of this
// invocation.
func (c FileSystemGlobFuncCall) Args() []interface{} {
return []interface{}{c.Arg0}
}
// Results returns an interface slice containing the results of this
// invocation.
func (c FileSystemGlobFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1}
}
// FileSystemListFilesFunc describes the behavior when the ListFiles method
// of the parent MockFileSystem instance is invoked.
type FileSystemListFilesFunc struct {
defaultHook func(string) ([]string, error)
hooks []func(string) ([]string, error)
history []FileSystemListFilesFuncCall
mutex sync.Mutex
}
// ListFiles delegates to the next hook function in the queue and stores the
// parameter and result values of this invocation.
func (m *MockFileSystem) ListFiles(v0 string) ([]string, error) {
r0, r1 := m.ListFilesFunc.nextHook()(v0)
m.ListFilesFunc.appendCall(FileSystemListFilesFuncCall{v0, r0, r1})
return r0, r1
}
// SetDefaultHook sets function that is called when the ListFiles method of
// the parent MockFileSystem instance is invoked and the hook queue is
// empty.
func (f *FileSystemListFilesFunc) SetDefaultHook(hook func(string) ([]string, error)) {
f.defaultHook = hook
}
// PushHook adds a function to the end of hook queue. Each invocation of the
// ListFiles method of the parent MockFileSystem instance invokes the hook
// at the front of the queue and discards it. After the queue is empty, the
// default hook function is invoked for any future action.
func (f *FileSystemListFilesFunc) PushHook(hook func(string) ([]string, error)) {
f.mutex.Lock()
f.hooks = append(f.hooks, hook)
f.mutex.Unlock()
}
// SetDefaultReturn calls SetDefaultDefaultHook with a function that returns
// the given values.
func (f *FileSystemListFilesFunc) SetDefaultReturn(r0 []string, r1 error) {
f.SetDefaultHook(func(string) ([]string, error) {
return r0, r1
})
}
// PushReturn calls PushDefaultHook with a function that returns the given
// values.
func (f *FileSystemListFilesFunc) PushReturn(r0 []string, r1 error) {
f.PushHook(func(string) ([]string, error) {
return r0, r1
})
}
func (f *FileSystemListFilesFunc) nextHook() func(string) ([]string, error) {
f.mutex.Lock()
defer f.mutex.Unlock()
if len(f.hooks) == 0 {
return f.defaultHook
}
hook := f.hooks[0]
f.hooks = f.hooks[1:]
return hook
}
func (f *FileSystemListFilesFunc) appendCall(r0 FileSystemListFilesFuncCall) {
f.mutex.Lock()
f.history = append(f.history, r0)
f.mutex.Unlock()
}
// History returns a sequence of FileSystemListFilesFuncCall objects
// describing the invocations of this function.
func (f *FileSystemListFilesFunc) History() []FileSystemListFilesFuncCall {
f.mutex.Lock()
history := make([]FileSystemListFilesFuncCall, len(f.history))
copy(history, f.history)
f.mutex.Unlock()
return history
}
// FileSystemListFilesFuncCall is an object that describes an invocation of
// method ListFiles on an instance of MockFileSystem.
type FileSystemListFilesFuncCall struct {
// Arg0 is the value of the 1st argument passed to this method
// invocation.
Arg0 string
// Result0 is the value of the 1st result returned from this method
// invocation.
Result0 []string
// Result1 is the value of the 2nd result returned from this method
// invocation.
Result1 error
}
// Args returns an interface slice containing the arguments of this
// invocation.
func (c FileSystemListFilesFuncCall) Args() []interface{} {
return []interface{}{c.Arg0}
}
// Results returns an interface slice containing the results of this
// invocation.
func (c FileSystemListFilesFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1}
}
// FileSystemReadFileFunc describes the behavior when the ReadFile method of
// the parent MockFileSystem instance is invoked.
type FileSystemReadFileFunc struct {
defaultHook func(string) ([]byte, error)
hooks []func(string) ([]byte, error)
history []FileSystemReadFileFuncCall
mutex sync.Mutex
}
// ReadFile delegates to the next hook function in the queue and stores the
// parameter and result values of this invocation.
func (m *MockFileSystem) ReadFile(v0 string) ([]byte, error) {
r0, r1 := m.ReadFileFunc.nextHook()(v0)
m.ReadFileFunc.appendCall(FileSystemReadFileFuncCall{v0, r0, r1})
return r0, r1
}
// SetDefaultHook sets function that is called when the ReadFile method of
// the parent MockFileSystem instance is invoked and the hook queue is
// empty.
func (f *FileSystemReadFileFunc) SetDefaultHook(hook func(string) ([]byte, error)) {
f.defaultHook = hook
}
// PushHook adds a function to the end of hook queue. Each invocation of the
// ReadFile method of the parent MockFileSystem instance invokes the hook at
// the front of the queue and discards it. After the queue is empty, the
// default hook function is invoked for any future action.
func (f *FileSystemReadFileFunc) PushHook(hook func(string) ([]byte, error)) {
f.mutex.Lock()
f.hooks = append(f.hooks, hook)
f.mutex.Unlock()
}
// SetDefaultReturn calls SetDefaultDefaultHook with a function that returns
// the given values.
func (f *FileSystemReadFileFunc) SetDefaultReturn(r0 []byte, r1 error) {
f.SetDefaultHook(func(string) ([]byte, error) {
return r0, r1
})
}
// PushReturn calls PushDefaultHook with a function that returns the given
// values.
func (f *FileSystemReadFileFunc) PushReturn(r0 []byte, r1 error) {
f.PushHook(func(string) ([]byte, error) {
return r0, r1
})
}
func (f *FileSystemReadFileFunc) nextHook() func(string) ([]byte, error) {
f.mutex.Lock()
defer f.mutex.Unlock()
if len(f.hooks) == 0 {
return f.defaultHook
}
hook := f.hooks[0]
f.hooks = f.hooks[1:]
return hook
}
func (f *FileSystemReadFileFunc) appendCall(r0 FileSystemReadFileFuncCall) {
f.mutex.Lock()
f.history = append(f.history, r0)
f.mutex.Unlock()
}
// History returns a sequence of FileSystemReadFileFuncCall objects
// describing the invocations of this function.
func (f *FileSystemReadFileFunc) History() []FileSystemReadFileFuncCall {
f.mutex.Lock()
history := make([]FileSystemReadFileFuncCall, len(f.history))
copy(history, f.history)
f.mutex.Unlock()
return history
}
// FileSystemReadFileFuncCall is an object that describes an invocation of
// method ReadFile on an instance of MockFileSystem.
type FileSystemReadFileFuncCall struct {
// Arg0 is the value of the 1st argument passed to this method
// invocation.
Arg0 string
// Result0 is the value of the 1st result returned from this method
// invocation.
Result0 []byte
// Result1 is the value of the 2nd result returned from this method
// invocation.
Result1 error
}
// Args returns an interface slice containing the arguments of this
// invocation.
func (c FileSystemReadFileFuncCall) Args() []interface{} {
return []interface{}{c.Arg0}
}
// Results returns an interface slice containing the results of this
// invocation.
func (c FileSystemReadFileFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1}
}