distribution/notifications/metrics_test.go
Noah Treuhaft 9a58c91051 notifications: fix expvar for Go 1.7
Remove EndpointConfig.Transport from the return value of the
registry.notifications.endpoints expvar.Func.  It results in an empty
value for that expvar variable under Go 1.7 because it is a non-nil
*http.Transport, which Go 1.7 can no longer encode as JSON.

Signed-off-by: Noah Treuhaft <noah.treuhaft@docker.com>
2017-02-14 10:51:20 -08:00

28 lines
745 B
Go

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)
}
}