maxovertime_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package aggregator
  2. import (
  3. "reflect"
  4. "testing"
  5. "time"
  6. )
  7. func TestMaxOverTimeAggregator_Value(t *testing.T) {
  8. time1 := time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)
  9. type update struct {
  10. value float64
  11. timestamp time.Time
  12. additionalInformation map[string]string
  13. }
  14. tests := map[string]struct {
  15. updates []update
  16. want []MetricValue
  17. }{
  18. "no update": {
  19. updates: []update{},
  20. want: []MetricValue{
  21. {
  22. Value: 0,
  23. },
  24. },
  25. },
  26. "single update": {
  27. updates: []update{
  28. {
  29. value: 1,
  30. timestamp: time1,
  31. },
  32. },
  33. want: []MetricValue{
  34. {
  35. Value: 1,
  36. },
  37. },
  38. },
  39. "max first": {
  40. updates: []update{
  41. {
  42. value: 2,
  43. timestamp: time1,
  44. },
  45. {
  46. value: 1,
  47. timestamp: time1,
  48. },
  49. },
  50. want: []MetricValue{
  51. {
  52. Value: 2,
  53. },
  54. },
  55. },
  56. "max last": {
  57. updates: []update{
  58. {
  59. value: 1,
  60. timestamp: time1,
  61. },
  62. {
  63. value: 2,
  64. timestamp: time1,
  65. },
  66. },
  67. want: []MetricValue{
  68. {
  69. Value: 2,
  70. },
  71. },
  72. },
  73. }
  74. for name, tt := range tests {
  75. t.Run(name, func(t *testing.T) {
  76. agg := maxOverTimeAggregator{}
  77. for _, u := range tt.updates {
  78. agg.Update(u.value, u.timestamp, u.additionalInformation)
  79. }
  80. got := agg.Value()
  81. if !reflect.DeepEqual(got, tt.want) {
  82. t.Errorf("got = %v, want %v", got, tt.want)
  83. }
  84. })
  85. }
  86. }