-
Notifications
You must be signed in to change notification settings - Fork 1
/
graphite_test.go
117 lines (100 loc) · 1.69 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
package graphite
import (
"net"
"testing"
"time"
)
func TestNew(t *testing.T) {
conf := Config{
Address: "127.0.0.1:3300",
Prefix: "test",
Protocol: 12,
Timeout: 10 * time.Second,
}
server, err := New(&conf)
if err != ErrUnsupportedProto {
t.Fail()
}
if server != nil {
t.Fail()
}
}
func TestNew_ProtocolTCP(t *testing.T) {
var err error
var tcpServer Graphite
var l net.Listener
l, err = net.Listen("tcp", "127.0.0.1:3300")
if err != nil {
t.Error(err)
}
// Close the listener when test finish
defer func() {
if err := l.Close(); err != nil {
t.Log(err)
t.Fail()
}
}()
conf := &Config{
Address: "127.0.0.1:3300",
Prefix: "test",
Protocol: ProtocolTCP,
Timeout: 10 * time.Second,
}
tcpServer, err = New(conf)
if err != nil {
t.Fail()
}
srv, ok := tcpServer.(*GraphiteTCP)
if !ok {
t.Fail()
}
if srv.prefix != conf.Prefix {
t.Fail()
}
if srv.timeout != conf.Timeout {
t.Fail()
}
if srv.address != conf.Address {
t.Fail()
}
}
func TestNew_ProtocolUDP(t *testing.T) {
conf := Config{
Address: "127.0.0.1:3300",
Prefix: "test",
Protocol: ProtocolUDP,
}
udpServer, err := New(&conf)
if err != nil {
t.Fail()
}
srv, ok := udpServer.(*GraphiteUDP)
if !ok {
t.Fail()
}
if srv.prefix != conf.Prefix {
t.Fail()
}
if srv.address != conf.Address {
t.Fail()
}
}
func TestNew_ProtocolStdout(t *testing.T) {
conf := Config{
Address: "127.0.0.1:3300",
Prefix: "test",
Protocol: ProtocolStdout,
Timeout: 10 * time.Second,
}
stdoutServer, err := New(&conf)
if err != nil {
t.Fail()
}
srv, ok := stdoutServer.(*GraphiteStdout)
if !ok {
t.Fail()
}
if srv.prefix != conf.Prefix {
t.Fail()
}
}