Skip to content

Commit

Permalink
omit tags in json when empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Schwab committed Nov 28, 2013
1 parent da16708 commit f8cc9dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type Metric struct {
Key string
Value int64
Tags map[string]string
Tags map[string]string `json:"Tags,omitempty"`
}

func parseInt(s string) (i int) {
Expand Down
13 changes: 13 additions & 0 deletions metrix_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"github.com/stretchr/testify/assert"
"testing"
)
Expand All @@ -22,3 +23,15 @@ func TestRiakStatus(t *testing.T) {
assert.Equal(t, len(status.RingMembers), 5)
assert.Equal(t, status.RingMembers[0], "[email protected]")
}

func TestSerializeMetric(t *testing.T) {
m := &Metric{}
b, e := json.Marshal(m)
assert.Nil(t, e)
assert.NotContains(t, string(b), "Tags")

m.Tags = map[string]string{"a": "b"}
b, e = json.Marshal(m)
assert.Nil(t, e)
assert.Contains(t, string(b), "Tags")
}

0 comments on commit f8cc9dc

Please sign in to comment.