...
1 package notifications
2
3 import (
4 "encoding/json"
5 "expvar"
6 "testing"
7 )
8
9 func TestMetricsExpvar(t *testing.T) {
10 endpointsVar := expvar.Get("registry").(*expvar.Map).Get("notifications").(*expvar.Map).Get("endpoints")
11
12 var v interface{}
13 if err := json.Unmarshal([]byte(endpointsVar.String()), &v); err != nil {
14 t.Fatalf("unexpected error unmarshaling endpoints: %v", err)
15 }
16 if v != nil {
17 t.Fatalf("expected nil, got %#v", v)
18 }
19
20 NewEndpoint("x", "y", EndpointConfig{})
21
22 if err := json.Unmarshal([]byte(endpointsVar.String()), &v); err != nil {
23 t.Fatalf("unexpected error unmarshaling endpoints: %v", err)
24 }
25 if slice, ok := v.([]interface{}); !ok || len(slice) != 1 {
26 t.Logf("expected one-element []interface{}, got %#v", v)
27 }
28 }
29
View as plain text