github.com/galamsiva2020/kubernetes-heapster-monitoring@v0.0.0-20210823134957-3c1baa7c1e70/metrics/sinks/statsd/influxstatsd_formatter_test.go (about) 1 // Copyright 2016 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package statsd 16 17 import ( 18 "github.com/stretchr/testify/assert" 19 "k8s.io/heapster/metrics/core" 20 "testing" 21 ) 22 23 var ( 24 influxPrefix = "testprefix." 25 influxMetricName = "testmetric" 26 influxResourceName = "testresource" 27 ) 28 29 var influxLabels = map[string]string{ 30 "test_tag_1": "value1", 31 "test_tag_2": "value2", 32 "test_tag_3": "value3", 33 } 34 35 var influxMetricValue = core.MetricValue{ 36 MetricType: core.MetricGauge, 37 ValueType: core.ValueInt64, 38 IntValue: 1000, 39 } 40 41 func TestInfluxFormatWithoutLabels(t *testing.T) { 42 expectedMsg := "testprefix.testmetric:1000|g" 43 44 formatter := NewInfluxstatsdFormatter() 45 assert.NotNil(t, formatter) 46 47 msg, err := formatter.Format(influxPrefix, influxMetricName, nil, SnakeToLowerCamel, influxMetricValue) 48 assert.NoError(t, err) 49 assert.Equal(t, expectedMsg, msg) 50 } 51 52 func TestInfluxFormatWithLabels(t *testing.T) { 53 expectedMsg := "testprefix.testmetric,testTag1=value1,testTag2=value2,testTag3=value3:1000|g" 54 55 formatter := NewInfluxstatsdFormatter() 56 assert.NotNil(t, formatter) 57 58 msg, err := formatter.Format(influxPrefix, influxMetricName, influxLabels, SnakeToLowerCamel, influxMetricValue) 59 assert.NoError(t, err) 60 assert.Equal(t, expectedMsg, msg) 61 } 62 63 func TestInfluxFormatWithoutPrefix(t *testing.T) { 64 expectedMsg := "testmetric,TestTag1=value1,TestTag2=value2,TestTag3=value3:1000|g" 65 66 formatter := NewInfluxstatsdFormatter() 67 assert.NotNil(t, formatter) 68 69 msg, err := formatter.Format("", influxMetricName, influxLabels, SnakeToUpperCamel, influxMetricValue) 70 assert.NoError(t, err) 71 assert.Equal(t, expectedMsg, msg) 72 }