forked from stuartnelson3/twemproxy_exporter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
76 lines (60 loc) · 1.53 KB
/
main_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
package main
import (
"io"
"net"
"os"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestUnmarshalSimple(t *testing.T) {
l, err := net.Listen("tcp", "0.0.0.0:")
if err != nil {
t.Fatalf("failed to create tcp listener: %v", err)
}
defer l.Close()
go func() {
conn, err := l.Accept()
require.NoError(t, err)
defer conn.Close()
f, err := os.Open("testdata/simple.json")
require.NoError(t, err)
defer f.Close()
_, err = io.Copy(conn, f)
require.NoError(t, err)
}()
e := newExporter(l.Addr().String(), time.Second)
st, err := e.collect()
require.NoError(t, err)
require.Equal(t, 5.0, st.CurrConnections)
require.Equal(t, "nutcracker", st.Service)
proxied, ok := st.Pools["proxied"]
require.True(t, ok)
require.Equal(t, 65.0, proxied.ClientEOF)
require.Equal(t, 3, len(proxied.Servers))
require.Equal(t, 1495.0, proxied.Servers["memcached-1"].RequestBytes)
}
func TestUnmarshalFull(t *testing.T) {
l, err := net.Listen("tcp", "0.0.0.0:")
if err != nil {
t.Fatalf("failed to create tcp listener: %v", err)
}
defer l.Close()
go func() {
conn, err := l.Accept()
require.NoError(t, err)
defer conn.Close()
f, err := os.Open("testdata/full.json")
require.NoError(t, err)
defer f.Close()
_, err = io.Copy(conn, f)
require.NoError(t, err)
}()
e := newExporter(l.Addr().String(), time.Second)
st, err := e.collect()
require.NoError(t, err)
require.Equal(t, 5, len(st.Pools))
beta, ok := st.Pools["beta"]
require.True(t, ok)
require.Equal(t, 33.0, beta.Servers["server1"].Requests)
}