-
Notifications
You must be signed in to change notification settings - Fork 11
/
tcp_integration_test.go
90 lines (84 loc) · 1.71 KB
/
tcp_integration_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
// +build integration
package riemanngo
import (
"testing"
"time"
)
func TestSendEventTcp(t *testing.T) {
c := NewTCPClient("127.0.0.1:5555", 5*time.Second)
err := c.Connect()
defer c.Close()
if err != nil {
t.Error("Error Tcp client Connect")
}
result, err := SendEvent(c, &Event{
Service: "LOOOl",
Metric: 100,
Tags: []string{"nonblocking"},
})
if !*result.Ok {
t.Error("Error Tcp client SendEvent")
}
}
func TestSendEventsTcp(t *testing.T) {
c := NewTCPClient("127.0.0.1:5555", 5*time.Second)
err := c.Connect()
defer c.Close()
if err != nil {
t.Error("Error Tcp client Connect")
}
events := []Event{
{
Service: "hello",
Metric: 100,
Tags: []string{"hello"},
},
{
Service: "goodbye",
Metric: 200,
Tags: []string{"goodbye"},
},
}
result, err := SendEvents(c, &events)
if !*result.Ok {
t.Error("Error Tcp client SendEvent")
}
}
func TestQueryIndex(t *testing.T) {
c := NewTCPClient("127.0.0.1:5555", 5*time.Second)
err := c.Connect()
defer c.Close()
if err != nil {
t.Error("Error Tcp client Connect")
}
events := []Event{
{
Host: "foobaz",
Service: "golang",
Metric: 100,
Tags: []string{"hello"},
},
{
Host: "foobar",
Service: "golang",
Metric: 200,
Tags: []string{"goodbye"},
},
}
result, err := SendEvents(c, &events)
if !*result.Ok {
t.Error("Error Tcp client SendEvent")
}
queryResult, err := c.QueryIndex("(service = \"golang\")")
if len(queryResult) != 2 {
t.Error("Error Tcp client QueryIndex")
}
}
func TestTcpConnec(t *testing.T) {
c := NewTCPClient("does.not.exists:8888", 5*time.Second)
// should produce an error
err := c.Connect()
if err == nil {
t.Error("Error, should fail")
}
}