-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmocks_test.go
56 lines (45 loc) · 1.13 KB
/
mocks_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
package main
import (
"context"
"github.com/kkentzo/tagger/indexers"
"github.com/kkentzo/tagger/watchers"
"github.com/stretchr/testify/mock"
)
type MockIndexer struct {
mock.Mock
}
func (indexer *MockIndexer) Create(root string) indexers.Indexable {
args := indexer.Called(root)
return args.Get(0).(indexers.Indexable)
}
func (indexer *MockIndexer) Index(root string, event watchers.Event) {
indexer.Called(root, event)
}
func (indexer *MockIndexer) CreateWatcher(root string) watchers.Watchable {
args := indexer.Called(root)
return args.Get(0).(watchers.Watchable)
}
type MockWatcher struct {
mock.Mock
}
func CreateMockWatcher() *MockWatcher {
watcher := &MockWatcher{}
watcher.On("Watch", mock.AnythingOfType("*context.cancelCtx"))
watcher.On("Close")
watcher.On("Events")
return watcher
}
func (watcher *MockWatcher) Watch(ctx context.Context) {
watcher.Called(ctx)
}
func (watcher *MockWatcher) Events() chan watchers.Event {
args := watcher.Called()
if len(args) > 0 {
return args.Get(0).(chan watchers.Event)
} else {
return make(chan watchers.Event)
}
}
func (watcher *MockWatcher) Close() {
watcher.Called()
}