/
watcher.go
83 lines (72 loc) · 2.59 KB
/
watcher.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
/*
* Copyright (c) 2017, The Easegress Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package clustertest
import (
"github.com/megaease/easegress/v2/pkg/cluster"
clientv3 "go.etcd.io/etcd/client/v3"
)
// MockedWatcher defines a mocked watcher
type MockedWatcher struct {
MockedWatch func(key string) (<-chan *string, error)
MockedWatchPrefix func(prefix string) (<-chan map[string]*string, error)
MockedWatchRaw func(key string) (<-chan *clientv3.Event, error)
MockedWatchRawPrefix func(prefix string) (<-chan map[string]*clientv3.Event, error)
MockedWatchWithOp func(key string, ops ...cluster.ClientOp) (<-chan map[string]*string, error)
MockedClose func()
}
var _ cluster.Watcher = (*MockedWatcher)(nil)
// NewMockedWatcher return MockedWatcher
func NewMockedWatcher() *MockedWatcher {
return &MockedWatcher{}
}
// Watch implements interface function Watch
func (w *MockedWatcher) Watch(key string) (<-chan *string, error) {
if w.MockedWatch != nil {
return w.MockedWatch(key)
}
return nil, nil
}
// WatchPrefix implements interface function WatchPrefix
func (w *MockedWatcher) WatchPrefix(prefix string) (<-chan map[string]*string, error) {
if w.MockedWatchPrefix != nil {
return w.MockedWatchPrefix(prefix)
}
return nil, nil
}
// WatchRaw implements interface function WatchRaw
func (w *MockedWatcher) WatchRaw(key string) (<-chan *clientv3.Event, error) {
if w.MockedWatchRaw != nil {
return w.MockedWatchRaw(key)
}
return nil, nil
}
// WatchRawPrefix implements interface function WatchRawPrefix
func (w *MockedWatcher) WatchRawPrefix(prefix string) (<-chan map[string]*clientv3.Event, error) {
if w.MockedWatchRawPrefix != nil {
return w.MockedWatchRawPrefix(prefix)
}
return nil, nil
}
// WatchWithOp implements interface function WatchWithOp
func (w *MockedWatcher) WatchWithOp(key string, ops ...cluster.ClientOp) (<-chan map[string]*string, error) {
if w.MockedWatchWithOp != nil {
return w.MockedWatchWithOp(key, ops...)
}
return nil, nil
}
// Close implements interface function Close
func (w *MockedWatcher) Close() {}