maxovertime_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. "single update": {
  23. updates: []update{
  24. {
  25. value: 1,
  26. timestamp: time1,
  27. },
  28. },
  29. want: []MetricValue{
  30. {
  31. Value: 1,
  32. },
  33. },
  34. },
  35. "max first": {
  36. updates: []update{
  37. {
  38. value: 2,
  39. timestamp: time1,
  40. },
  41. {
  42. value: 1,
  43. timestamp: time1,
  44. },
  45. },
  46. want: []MetricValue{
  47. {
  48. Value: 2,
  49. },
  50. },
  51. },
  52. "max last": {
  53. updates: []update{
  54. {
  55. value: 1,
  56. timestamp: time1,
  57. },
  58. {
  59. value: 2,
  60. timestamp: time1,
  61. },
  62. },
  63. want: []MetricValue{
  64. {
  65. Value: 2,
  66. },
  67. },
  68. },
  69. }
  70. for name, tt := range tests {
  71. t.Run(name, func(t *testing.T) {
  72. agg := maxOverTimeAggregator{}
  73. for _, u := range tt.updates {
  74. agg.Update(u.value, u.timestamp, u.additionalInformation)
  75. }
  76. got := agg.Value()
  77. if !reflect.DeepEqual(got, tt.want) {
  78. t.Errorf("got = %v, want %v", got, tt.want)
  79. }
  80. })
  81. }
  82. }