From 10b3e4577501ddba228721754339145f7b9b15ec Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Tue, 8 Jan 2019 17:57:38 -0800 Subject: [PATCH] Sort fields in nowmetric test --- plugins/serializers/nowmetric/nowmetric_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/serializers/nowmetric/nowmetric_test.go b/plugins/serializers/nowmetric/nowmetric_test.go index d326cef8c..e49b81c2d 100644 --- a/plugins/serializers/nowmetric/nowmetric_test.go +++ b/plugins/serializers/nowmetric/nowmetric_test.go @@ -2,14 +2,14 @@ package nowmetric import ( "fmt" + "sort" "testing" "time" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/metric" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func MustMetric(v telegraf.Metric, err error) telegraf.Metric { @@ -136,6 +136,11 @@ func TestSerializeMultiFields(t *testing.T) { m, err := metric.New("cpu", tags, fields, now) assert.NoError(t, err) + // Sort for predictable field order + sort.Slice(m.FieldList(), func(i, j int) bool { + return m.FieldList()[i].Key < m.FieldList()[j].Key + }) + s, _ := NewSerializer() var buf []byte buf, err = s.Serialize(m)