2018-02-23 03:56:08 -06: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 09:04:35 -06:00
|
|
|
if s := b.String(); s != "{\"counter\":{\"count\":0}}\n" {
|
2024-10-14 12:25:22 -05:00
|
|
|
t.Fatal(s)
|
2018-02-23 03:56:08 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|