github.com/RollNA/go-ethereum@v1.9.7/metrics/json_test.go (about)

     1  package metrics
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/json"
     6  	"testing"
     7  )
     8  
     9  func TestRegistryMarshallJSON(t *testing.T) {
    10  	b := &bytes.Buffer{}
    11  	enc := json.NewEncoder(b)
    12  	r := NewRegistry()
    13  	r.Register("counter", NewCounter())
    14  	enc.Encode(r)
    15  	if s := b.String(); "{\"counter\":{\"count\":0}}\n" != s {
    16  		t.Fatalf(s)
    17  	}
    18  }
    19  
    20  func TestRegistryWriteJSONOnce(t *testing.T) {
    21  	r := NewRegistry()
    22  	r.Register("counter", NewCounter())
    23  	b := &bytes.Buffer{}
    24  	WriteJSONOnce(r, b)
    25  	if s := b.String(); s != "{\"counter\":{\"count\":0}}\n" {
    26  		t.Fail()
    27  	}
    28  }