-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathtest_helper.go
More file actions
59 lines (49 loc) · 1.53 KB
/
test_helper.go
File metadata and controls
59 lines (49 loc) · 1.53 KB
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
package k8s
import "k8s.io/api/core/v1"
type MockEndpointsWatcher struct {
HostReceived string
ListenerSubscribed EndpointsListener
ListenerUnsubscribed EndpointsListener
ServiceToReturn *v1.Service
ExistsToReturn bool
ErrToReturn error
}
func (m *MockEndpointsWatcher) GetService(service string) (*v1.Service, bool, error) {
m.HostReceived = service
return m.ServiceToReturn, m.ExistsToReturn, m.ErrToReturn
}
func (m *MockEndpointsWatcher) Subscribe(service string, port uint32, listener EndpointsListener) error {
m.ListenerSubscribed = listener
return m.ErrToReturn
}
func (m *MockEndpointsWatcher) Unsubscribe(service string, port uint32, listener EndpointsListener) error {
m.ListenerUnsubscribed = listener
return m.ErrToReturn
}
func (m *MockEndpointsWatcher) Run() error {
return m.ErrToReturn
}
func (m *MockEndpointsWatcher) Stop() {}
type InMemoryPodIndex struct {
BackingMap map[string][]*v1.Pod
}
func (i *InMemoryPodIndex) GetPod(key string) (*v1.Pod, error) {
return i.BackingMap[key][0], nil
}
func (i *InMemoryPodIndex) GetPodsByIndex(key string) ([]*v1.Pod, error) {
return i.BackingMap[key], nil
}
func (i *InMemoryPodIndex) List() ([]*v1.Pod, error) {
var pods []*v1.Pod
for _, byIndex := range i.BackingMap {
for _, pod := range byIndex {
pods = append(pods, pod)
}
}
return pods, nil
}
func (i *InMemoryPodIndex) Run() error { return nil }
func (i *InMemoryPodIndex) Stop() {}
func NewEmptyPodIndex() PodIndex {
return &InMemoryPodIndex{BackingMap: map[string][]*v1.Pod{}}
}