Browse Source

Add a test for JSON encoding

This is mostly as an example for how to use it.
Richard Crowley 11 years ago
parent
commit
4d17aae18c
1 changed files with 18 additions and 0 deletions
  1. 18 0
      json_test.go

+ 18 - 0
json_test.go

@@ -0,0 +1,18 @@
+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)
+	if s := b.String(); "{\"counter\":{\"count\":0}}\n" != s {
+		t.Fatalf(s)
+	}
+}