-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaggregator_mock_test.go
87 lines (77 loc) · 2.52 KB
/
aggregator_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package graphite
import (
"time"
)
// MockAggregator implements the Aggregator interface and it's ready to be used to mock it.
type MockAggregator struct {
Data map[string]int
MethodAddSum func(*MockAggregator, string, interface{})
MethodIncrease func(*MockAggregator, string)
MethodAddAverage func(*MockAggregator, string, interface{})
MethodSetActive func(*MockAggregator, string)
MethodSetInactive func(*MockAggregator, string)
MethodRun func(*MockAggregator, time.Duration, chan bool) Aggregator
MethodFlush func(*MockAggregator) (int, error)
MethodRetry func(*MockAggregator) (int, error)
}
// AddSum is an implementation of Aggregator interface to be used with the mocking object.
func (m *MockAggregator) AddSum(path string, value interface{}) {
if m.MethodAddSum != nil {
m.MethodAddSum(m, path, value)
return
}
m.Data[path] = value.(int)
}
// Increase is an implementation of Aggregator interface to be used with the mocking object.
func (m *MockAggregator) Increase(path string) {
if m.MethodIncrease != nil {
m.MethodIncrease(m, path)
return
}
m.Data[path] = 1
}
// AddAverage is an implementation of Aggregator interface to be used with the mocking object.
func (m *MockAggregator) AddAverage(path string, value interface{}) {
if m.MethodAddAverage != nil {
m.MethodAddAverage(m, path, value)
return
}
m.Data[path] = value.(int)
}
// SetActive is an implementation of Aggregator interface to be used with the mocking object.
func (m *MockAggregator) SetActive(path string) {
if m.MethodSetActive != nil {
m.MethodSetActive(m, path)
return
}
m.Data[path] = 1
}
// SetInactive is an implementation of Aggregator interface to be used with the mocking object.
func (m *MockAggregator) SetInactive(path string) {
if m.MethodSetInactive != nil {
m.MethodSetInactive(m, path)
return
}
m.Data[path] = 0
}
// Run is an implementation of Aggregator interface to be used with the mocking object.
func (m *MockAggregator) Run(period time.Duration, stop chan bool) Aggregator {
if m.MethodRun != nil {
return m.MethodRun(m, period, stop)
}
return m
}
// Flush is an implementation of Aggregator interface to be used with the mocking object.
func (m *MockAggregator) Flush() (int, error) {
if m.MethodFlush != nil {
return m.MethodFlush(m)
}
return 0, nil
}
// Retry is an implementation of Aggregator interface to be used with the mocking object.
func (m *MockAggregator) Retry() (int, error) {
if m.MethodRetry != nil {
return m.MethodRetry(m)
}
return 0, nil
}