From f046a292f02e68a3ea141206b11e89eae24cdb30 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Thu, 22 Mar 2018 17:32:37 -0700 Subject: [PATCH] Move metric.equal to test file --- metric/metric.go | 26 -------------------------- metric/metric_test.go | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/metric/metric.go b/metric/metric.go index 4df5ded2a08ea..4d237be615586 100644 --- a/metric/metric.go +++ b/metric/metric.go @@ -229,32 +229,6 @@ func (m *metric) IsAggregate() bool { return m.aggregate } -func (m *metric) equal(o *metric) bool { - if m.name != o.name || m.tm != o.tm { - return false - } - - if len(m.tags) != len(o.tags) || len(m.fields) != len(o.fields) { - return false - } - - for i, tag := range m.tags { - if tag.Key != o.tags[i].Key || tag.Value != o.tags[i].Value { - return false - } - } - - sort.Slice(m.fields, func(i, j int) bool { return m.fields[i].Key < m.fields[j].Key }) - sort.Slice(o.fields, func(i, j int) bool { return o.fields[i].Key < o.fields[j].Key }) - - for i, field := range m.fields { - if field.Key != o.fields[i].Key || field.Value != o.fields[i].Value { - return false - } - } - return true -} - func (m *metric) HashID() uint64 { h := fnv.New64a() h.Write([]byte(m.name)) diff --git a/metric/metric_test.go b/metric/metric_test.go index cf4ef229ab594..3260c1b901f7d 100644 --- a/metric/metric_test.go +++ b/metric/metric_test.go @@ -1,6 +1,7 @@ package metric import ( + "sort" "testing" "time" @@ -9,6 +10,32 @@ import ( "github.com/stretchr/testify/require" ) +func MetricEqual(lhs *metric, rhs *metric) bool { + if lhs.name != rhs.name || lhs.tm != rhs.tm { + return false + } + + if len(lhs.tags) != len(rhs.tags) || len(lhs.fields) != len(rhs.fields) { + return false + } + + for i, tag := range lhs.tags { + if tag.Key != rhs.tags[i].Key || tag.Value != rhs.tags[i].Value { + return false + } + } + + sort.Slice(lhs.fields, func(i, j int) bool { return lhs.fields[i].Key < lhs.fields[j].Key }) + sort.Slice(rhs.fields, func(i, j int) bool { return rhs.fields[i].Key < rhs.fields[j].Key }) + + for i, field := range lhs.fields { + if field.Key != rhs.fields[i].Key || field.Value != rhs.fields[i].Value { + return false + } + } + return true +} + func TestNewMetric(t *testing.T) { now := time.Now() @@ -193,12 +220,12 @@ func TestEquals(t *testing.T) { require.NoError(t, err) lhs := m1.(*metric) - require.True(t, lhs.equal(m2.(*metric))) + require.True(t, MetricEqual(lhs, m2.(*metric))) m3 := m2.Copy() - require.True(t, lhs.equal(m3.(*metric))) + require.True(t, MetricEqual(lhs, m3.(*metric))) m3.AddTag("a", "x") - require.False(t, lhs.equal(m3.(*metric))) + require.False(t, MetricEqual(lhs, m3.(*metric))) } func TestHashID(t *testing.T) {