This repository has been archived by the owner on Jun 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathgraphite_test.go
118 lines (95 loc) · 2.39 KB
/
graphite_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
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
113
114
115
116
117
118
package graphite
import (
"fmt"
"net"
"strings"
"testing"
)
const TCP = "tcp"
const UDP = "udp"
const NOP = "nop"
// Change these to be your own graphite server if you so please
var graphiteHost = "carbon.hostedgraphite.com"
var graphitePort = 2003
func TestNewGraphite(t *testing.T) {
gh, err := NewGraphite(graphiteHost, graphitePort)
if err != nil {
t.Error(err)
}
if _, ok := gh.conn.(*net.TCPConn); !ok {
t.Error("GraphiteHost.conn is not a TCP connection")
}
}
func TestNewGraphiteWithMetricPrefix(t *testing.T) {
prefix := "test"
gh, err := NewGraphiteWithMetricPrefix(graphiteHost, graphitePort, prefix)
if err != nil {
t.Error(err)
}
if _, ok := gh.conn.(*net.TCPConn); !ok {
t.Error("GraphiteHost.conn is not a TCP connection")
}
}
func TestNewGraphiteUDP(t *testing.T) {
gh, err := NewGraphiteUDP(graphiteHost, graphitePort)
if err != nil {
t.Error(err)
}
if _, ok := gh.conn.(*net.UDPConn); !ok {
t.Error("GraphiteHost.conn is not a UDP connection")
}
}
func TestGraphiteFactoryTCP(t *testing.T) {
gr, err := GraphiteFactory(TCP, graphiteHost, graphitePort, "")
if err != nil {
t.Error(err)
}
if _, ok := gr.conn.(*net.TCPConn); !ok {
t.Error("GraphiteHost.conn is not a TCP connection")
}
}
func TestGraphiteFactoryTCPWithPrefix(t *testing.T) {
prefix := "test"
gr, err := GraphiteFactory(TCP, graphiteHost, graphitePort, prefix)
if err != nil {
t.Error(err)
}
if _, ok := gr.conn.(*net.TCPConn); !ok {
t.Error("GraphiteHost.conn is not a TCP connection")
}
if !strings.EqualFold(prefix, gr.Prefix) {
t.Error(fmt.Sprintf("Wrong prefix is set expected %s actual %s",
prefix,
gr.Prefix))
}
}
func TestGraphiteFactoryUDP(t *testing.T) {
gr, err := GraphiteFactory(UDP, graphiteHost, graphitePort, "")
if err != nil {
t.Error(err)
}
if _, ok := gr.conn.(*net.UDPConn); !ok {
t.Error("GraphiteHost.conn is not a UDP connection")
}
}
func TestGraphiteFactoryNop(t *testing.T) {
gr, err := GraphiteFactory(NOP, graphiteHost, graphitePort, "")
if err != nil {
t.Error(err)
}
if !gr.IsNop() {
t.Error("GraphiteHost is not NOP")
}
}
// Uncomment the following method to test sending an actual metric to graphite
//
//func TestSendMetric(t *testing.T) {
// gh, err := NewGraphite(graphiteHost, graphitePort)
// if err != nil {
// t.Error(err)
// }
// err = gh.SimpleSend("stats.test.metric11", "1")
// if err != nil {
// t.Error(err)
// }
//}