diff --git a/helpers/metric.go b/helpers/metric.go index 1f7e34e..9a7c454 100644 --- a/helpers/metric.go +++ b/helpers/metric.go @@ -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 { diff --git a/helpers/metric_test.go b/helpers/metric_test.go index 811d35a..257f68d 100644 --- a/helpers/metric_test.go +++ b/helpers/metric_test.go @@ -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]) + } }