carbon_formatter_test.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package sumologicexporter
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestCarbon2TagString(t *testing.T) {
  9. metric := exampleIntMetric()
  10. data := carbon2TagString(metric)
  11. assert.Equal(t, "test=test_value test2=second_value metric=test.metric.data unit=bytes", data)
  12. metric = exampleIntGaugeMetric()
  13. data = carbon2TagString(metric)
  14. assert.Equal(t, "foo=bar metric=gauge_metric_name", data)
  15. metric = exampleDoubleSumMetric()
  16. data = carbon2TagString(metric)
  17. assert.Equal(t, "foo=bar metric=sum_metric_double_test", data)
  18. metric = exampleDoubleGaugeMetric()
  19. data = carbon2TagString(metric)
  20. assert.Equal(t, "foo=bar metric=gauge_metric_name_double_test", data)
  21. }
  22. func TestCarbonMetricTypeIntGauge(t *testing.T) {
  23. metric := exampleIntGaugeMetric()
  24. result := carbon2Metric2String(metric)
  25. expected := `foo=bar metric=gauge_metric_name 124 1608124661
  26. foo=bar metric=gauge_metric_name 245 1608124662`
  27. assert.Equal(t, expected, result)
  28. }
  29. func TestCarbonMetricTypeDoubleGauge(t *testing.T) {
  30. metric := exampleDoubleGaugeMetric()
  31. result := carbon2Metric2String(metric)
  32. expected := `foo=bar metric=gauge_metric_name_double_test 33.4 1608124661
  33. foo=bar metric=gauge_metric_name_double_test 56.8 1608124662`
  34. assert.Equal(t, expected, result)
  35. }
  36. func TestCarbonMetricTypeIntSum(t *testing.T) {
  37. metric := exampleIntSumMetric()
  38. result := carbon2Metric2String(metric)
  39. expected := `foo=bar metric=sum_metric_int_test 45 1608124444
  40. foo=bar metric=sum_metric_int_test 1238 1608124699`
  41. assert.Equal(t, expected, result)
  42. }
  43. func TestCarbonMetricTypeDoubleSum(t *testing.T) {
  44. metric := exampleDoubleSumMetric()
  45. result := carbon2Metric2String(metric)
  46. expected := `foo=bar metric=sum_metric_double_test 45.6 1618124444
  47. foo=bar metric=sum_metric_double_test 1238.1 1608424699`
  48. assert.Equal(t, expected, result)
  49. }
  50. func TestCarbonMetricTypeSummary(t *testing.T) {
  51. metric := exampleSummaryMetric()
  52. result := carbon2Metric2String(metric)
  53. expected := ``
  54. assert.Equal(t, expected, result)
  55. metric = buildExampleSummaryMetric(false)
  56. result = carbon2Metric2String(metric)
  57. assert.Equal(t, expected, result)
  58. }
  59. func TestCarbonMetricTypeHistogram(t *testing.T) {
  60. metric := exampleHistogramMetric()
  61. result := carbon2Metric2String(metric)
  62. expected := ``
  63. assert.Equal(t, expected, result)
  64. metric = buildExampleHistogramMetric(false)
  65. result = carbon2Metric2String(metric)
  66. assert.Equal(t, expected, result)
  67. }