-
Notifications
You must be signed in to change notification settings - Fork 11
/
router_test.go
62 lines (52 loc) · 1.72 KB
/
router_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
package metrics
import (
"crypto/tls"
"strings"
"testing"
metrics "github.com/rcrowley/go-metrics"
)
func TestRouterMetrics(t *testing.T) {
p := metrics.NewRegistry()
rm := NewRouterMetrics(&p)
rm.Connection(nil)
rm.Connection(&tls.ConnectionState{Version: tls.VersionTLS11, CipherSuite: tls.TLS_RSA_WITH_AES_128_GCM_SHA256})
rm.Disconnection()
rm.Connection(nil)
rm.Connection(nil)
rm.Connection(nil)
rm.Aggregate()
rm.Connection(&tls.ConnectionState{Version: tls.VersionTLS12, CipherSuite: tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA})
rm.Disconnection()
rm.Disconnection()
rm.Disconnection()
rm.Aggregate()
rm.Disconnection()
p.Each(func(name string, v interface{}) {
if !strings.HasPrefix(name, "router.") {
t.Errorf("Unexpected metric: %s", name)
}
})
for k, want := range map[string]int64{
"router.connected": 0,
"router.disconnected": 1,
"router.connected-total": 6,
"router.disconnected-total": 4,
"router.connected-gauge": 1,
"router.disconnected-gauge": 3,
"router.tls_cipher.TLS_RSA_WITH_AES_128_GCM_SHA256.count": 1,
"router.tls_cipher.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA.count": 1,
"router.tls_version.VersionTLS11.count": 1,
"router.tls_version.VersionTLS12.count": 1,
} {
var have int64
switch metric := p.Get(k).(type) {
case metrics.Counter:
have = metric.Count()
case metrics.Gauge:
have = metric.Value()
}
if have != want {
t.Errorf("Unexpected value for %s. Have: %d, want: %d", k, have, want)
}
}
}