File: metrics_test.go

package info (click to toggle)
docker-registry 2.8.1%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,148 kB
  • sloc: sh: 331; makefile: 82
file content (28 lines) | stat: -rw-r--r-- 745 bytes parent folder | download | duplicates (6)
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
package notifications

import (
	"encoding/json"
	"expvar"
	"testing"
)

func TestMetricsExpvar(t *testing.T) {
	endpointsVar := expvar.Get("registry").(*expvar.Map).Get("notifications").(*expvar.Map).Get("endpoints")

	var v interface{}
	if err := json.Unmarshal([]byte(endpointsVar.String()), &v); err != nil {
		t.Fatalf("unexpected error unmarshaling endpoints: %v", err)
	}
	if v != nil {
		t.Fatalf("expected nil, got %#v", v)
	}

	NewEndpoint("x", "y", EndpointConfig{})

	if err := json.Unmarshal([]byte(endpointsVar.String()), &v); err != nil {
		t.Fatalf("unexpected error unmarshaling endpoints: %v", err)
	}
	if slice, ok := v.([]interface{}); !ok || len(slice) != 1 {
		t.Logf("expected one-element []interface{}, got %#v", v)
	}
}