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