-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphite_mock_test.go
68 lines (60 loc) · 1.96 KB
/
graphite_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
package graphite
import (
"bytes"
"fmt"
)
// MockGraphite implements the interface Graphite
type MockGraphite struct {
Extra map[string]interface{}
Data map[string]string
MethodSend func(*MockGraphite, string, string) (int, error)
MethodSendBuffer func(*MockGraphite, *bytes.Buffer) (int, error)
MethodNewAggregator func(*MockGraphite) Aggregator
MethodConnect func(*MockGraphite) error
MethodReconnect func(*MockGraphite) error
MethodDisconnect func(*MockGraphite) error
}
// Send is an implementation of Graphite interface to be used with the mocking object.
func (m *MockGraphite) Send(path string, value string) (int, error) {
if m.MethodSend != nil {
return m.MethodSend(m, path, value)
}
m.Data[path] = fmt.Sprintf("%s:%s", path, value)
return 0, nil
}
// SendBuffer is an implementation of Graphite interface to be used with the mocking object.
func (m *MockGraphite) SendBuffer(buffer *bytes.Buffer) (int, error) {
if m.MethodSendBuffer != nil {
return m.MethodSendBuffer(m, buffer)
}
m.Data["buffer"] = buffer.String()
return 0, nil
}
// NewAggregator is an implementation of Graphite interface to be used with the mocking object.
func (m *MockGraphite) NewAggregator() Aggregator {
if m.MethodNewAggregator != nil {
return m.MethodNewAggregator(m)
}
return &MockAggregator{}
}
// Connect is an implementation of Graphite interface to be used with the mocking object.
func (m *MockGraphite) Connect() error {
if m.MethodConnect != nil {
return m.MethodConnect(m)
}
return nil
}
// Reconnect is an implementation of Graphite interface to be used with the mocking object.
func (m *MockGraphite) Reconnect() error {
if m.MethodReconnect != nil {
return m.MethodReconnect(m)
}
return nil
}
// Disconnect is an implementation of Graphite interface to be used with the mocking object.
func (m *MockGraphite) Disconnect() error {
if m.MethodDisconnect != nil {
return m.MethodDisconnect(m)
}
return nil
}