From 332f678afbaf216ea3a7a2886ce3b15156b7c138 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Thu, 1 Dec 2016 18:16:52 +0000 Subject: [PATCH] JSON serializer: include unit test with escapes --- plugins/serializers/json/json_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plugins/serializers/json/json_test.go b/plugins/serializers/json/json_test.go index 127bf237a..bf350fd14 100644 --- a/plugins/serializers/json/json_test.go +++ b/plugins/serializers/json/json_test.go @@ -85,3 +85,22 @@ func TestSerializeMultiFields(t *testing.T) { expS := []string{fmt.Sprintf("{\"fields\":{\"usage_idle\":90,\"usage_total\":8559615},\"name\":\"cpu\",\"tags\":{\"cpu\":\"cpu0\"},\"timestamp\":%d}", now.Unix())} assert.Equal(t, expS, mS) } + +func TestSerializeMetricWithEscapes(t *testing.T) { + now := time.Now() + tags := map[string]string{ + "cpu tag": "cpu0", + } + fields := map[string]interface{}{ + "U,age=Idle": int64(90), + } + m, err := telegraf.NewMetric("My CPU", tags, fields, now) + assert.NoError(t, err) + + s := JsonSerializer{} + mS, err := s.Serialize(m) + assert.NoError(t, err) + + expS := []string{fmt.Sprintf(`{"fields":{"U,age=Idle":90},"name":"My CPU","tags":{"cpu tag":"cpu0"},"timestamp":%d}`, now.Unix())} + assert.Equal(t, expS, mS) +}