2018-02-23 10:56:08 +01:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRegistryMarshallJSON(t *testing.T) {
|
|
|
|
b := &bytes.Buffer{}
|
|
|
|
enc := json.NewEncoder(b)
|
|
|
|
r := NewRegistry()
|
|
|
|
r.Register("counter", NewCounter())
|
|
|
|
enc.Encode(r)
|
2019-11-22 16:04:35 +01:00
|
|
|
if s := b.String(); s != "{\"counter\":{\"count\":0}}\n" {
|
2018-02-23 10:56:08 +01:00
|
|
|
t.Fatalf(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRegistryWriteJSONOnce(t *testing.T) {
|
|
|
|
r := NewRegistry()
|
|
|
|
r.Register("counter", NewCounter())
|
|
|
|
b := &bytes.Buffer{}
|
|
|
|
WriteJSONOnce(r, b)
|
|
|
|
if s := b.String(); s != "{\"counter\":{\"count\":0}}\n" {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|