info_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package aggregator
  2. import (
  3. "reflect"
  4. "testing"
  5. "time"
  6. )
  7. func TestInfoAggregator_AdditionInfo(t *testing.T) {
  8. type update struct {
  9. value float64
  10. timestamp time.Time
  11. additionalInformation map[string]string
  12. }
  13. tests := map[string]struct {
  14. updates []update
  15. want map[string]string
  16. }{
  17. "no update": {
  18. updates: []update{},
  19. want: nil,
  20. },
  21. "empty update": {
  22. updates: []update{
  23. {},
  24. },
  25. want: nil,
  26. },
  27. "single update": {
  28. updates: []update{
  29. {
  30. additionalInformation: map[string]string{
  31. "test": "test",
  32. },
  33. },
  34. },
  35. want: map[string]string{
  36. "test": "test",
  37. },
  38. },
  39. "double update": {
  40. updates: []update{
  41. {
  42. additionalInformation: map[string]string{
  43. "test": "test",
  44. },
  45. },
  46. {
  47. additionalInformation: map[string]string{
  48. "test2": "test2",
  49. },
  50. },
  51. },
  52. want: map[string]string{
  53. "test2": "test2",
  54. },
  55. },
  56. }
  57. for name, tt := range tests {
  58. t.Run(name, func(t *testing.T) {
  59. agg := infoAggregator{}
  60. for _, u := range tt.updates {
  61. agg.Update(u.value, u.timestamp, u.additionalInformation)
  62. }
  63. got := agg.AdditionInfo()
  64. if !reflect.DeepEqual(got, tt.want) {
  65. t.Errorf("got = %v, want %v", got, tt.want)
  66. }
  67. })
  68. }
  69. }