generated from cybozu-go/neco-template
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmock_test.go
69 lines (52 loc) · 1.25 KB
/
mock_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
package controllers
import (
"sync"
"github.com/cybozu-go/moco/clustering"
"k8s.io/apimachinery/pkg/types"
)
type mockManager struct {
mu sync.Mutex
clusters map[string]struct{}
updated []types.NamespacedName
}
var _ clustering.ClusterManager = &mockManager{}
func (m *mockManager) Update(key types.NamespacedName, origin string) {
m.mu.Lock()
defer m.mu.Unlock()
m.clusters[key.String()] = struct{}{}
}
func (m *mockManager) UpdateNoStart(key types.NamespacedName, origin string) {
m.mu.Lock()
defer m.mu.Unlock()
m.updated = append(m.updated, key)
}
func (m *mockManager) Stop(key types.NamespacedName) {
m.mu.Lock()
defer m.mu.Unlock()
delete(m.clusters, key.String())
}
func (m *mockManager) StopAll() {}
func (m *mockManager) Pause(key types.NamespacedName) {
m.mu.Lock()
defer m.mu.Unlock()
delete(m.clusters, key.String())
}
func (m *mockManager) getKeys() map[string]bool {
m.mu.Lock()
defer m.mu.Unlock()
keys := make(map[string]bool)
for k := range m.clusters {
keys[k] = true
}
return keys
}
func (m *mockManager) isUpdated(key types.NamespacedName) bool {
m.mu.Lock()
defer m.mu.Unlock()
for _, k := range m.updated {
if k.Namespace == key.Namespace && k.Name == key.Name {
return true
}
}
return false
}