Skip to content

Commit

Permalink
PMM-1772 Add another helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Dec 13, 2019
1 parent 2226bd0 commit 7442d2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions helpers/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type Metric struct {
Value float64
}

func (m *Metric) String() string {
return fmt.Sprintf("%+v", *m)
}

// Less returns true if m < m2 in some stable order. Can be used for sorting.
func (m *Metric) Less(m2 *Metric) bool {
if m.Name != m2.Name {
Expand Down
4 changes: 4 additions & 0 deletions helpers/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,8 @@ func TestLess(t *testing.T) {
if !reflect.DeepEqual(expected, actual) {
t.Errorf("Less:\nexpected = %+v\actual = %+v", expected, actual)
}

if s := expected[0].String(); s != "{Name:counter Help:metric description Labels:map[instance:test1 job:test] Type:COUNTER Value:36.6}" {
t.Errorf("Unexpected String(): %q for %#v", s, expected[0])
}
}

0 comments on commit 7442d2a

Please sign in to comment.