-
Notifications
You must be signed in to change notification settings - Fork 202
/
appStatusHandlerMock.go
112 lines (87 loc) · 1.9 KB
/
appStatusHandlerMock.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
package mock
import "sync"
// AppStatusHandlerMock -
type AppStatusHandlerMock struct {
mut sync.Mutex
data map[string]interface{}
}
// NewAppStatusHandlerMock -
func NewAppStatusHandlerMock() *AppStatusHandlerMock {
return &AppStatusHandlerMock{
data: make(map[string]interface{}),
}
}
// Increment -
func (ashm *AppStatusHandlerMock) Increment(key string) {
ashm.mut.Lock()
defer ashm.mut.Unlock()
v, ok := ashm.data[key]
if !ok {
return
}
vUint64, ok := v.(uint64)
if !ok {
return
}
ashm.data[key] = vUint64 + 1
}
// AddUint64 -
func (ashm *AppStatusHandlerMock) AddUint64(key string, val uint64) {
ashm.mut.Lock()
defer ashm.mut.Unlock()
v, ok := ashm.data[key]
if !ok {
return
}
vUint64, ok := v.(uint64)
if !ok {
return
}
ashm.data[key] = vUint64 + val
}
// Decrement -
func (ashm *AppStatusHandlerMock) Decrement(key string) {
ashm.mut.Lock()
defer ashm.mut.Unlock()
v, ok := ashm.data[key]
if !ok {
return
}
vUint64, ok := v.(uint64)
if !ok {
return
}
if vUint64 != 0 {
ashm.data[key] = vUint64 - 1
}
}
// SetInt64Value -
func (ashm *AppStatusHandlerMock) SetInt64Value(key string, value int64) {
ashm.mut.Lock()
defer ashm.mut.Unlock()
ashm.data[key] = value
}
// SetUInt64Value -
func (ashm *AppStatusHandlerMock) SetUInt64Value(key string, value uint64) {
ashm.mut.Lock()
defer ashm.mut.Unlock()
ashm.data[key] = value
}
// SetStringValue -
func (ashm *AppStatusHandlerMock) SetStringValue(key string, value string) {
ashm.mut.Lock()
defer ashm.mut.Unlock()
ashm.data[key] = value
}
// GetUint64 -
func (ashm *AppStatusHandlerMock) GetUint64(key string) uint64 {
ashm.mut.Lock()
defer ashm.mut.Unlock()
return ashm.data[key].(uint64)
}
// Close -
func (ashm *AppStatusHandlerMock) Close() {}
// IsInterfaceNil returns true if there is no value under the interface
func (ashm *AppStatusHandlerMock) IsInterfaceNil() bool {
return ashm == nil
}