| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package aggregator
- import (
- "reflect"
- "testing"
- "time"
- )
- func TestMaxOverTimeAggregator_Value(t *testing.T) {
- time1 := time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)
- type update struct {
- value float64
- timestamp time.Time
- additionalInformation map[string]string
- }
- tests := map[string]struct {
- updates []update
- want []MetricValue
- }{
- "no update": {
- updates: []update{},
- want: []MetricValue{
- {
- Value: 0,
- },
- },
- },
- "single update": {
- updates: []update{
- {
- value: 1,
- timestamp: time1,
- },
- },
- want: []MetricValue{
- {
- Value: 1,
- },
- },
- },
- "max first": {
- updates: []update{
- {
- value: 2,
- timestamp: time1,
- },
- {
- value: 1,
- timestamp: time1,
- },
- },
- want: []MetricValue{
- {
- Value: 2,
- },
- },
- },
- "max last": {
- updates: []update{
- {
- value: 1,
- timestamp: time1,
- },
- {
- value: 2,
- timestamp: time1,
- },
- },
- want: []MetricValue{
- {
- Value: 2,
- },
- },
- },
- }
- for name, tt := range tests {
- t.Run(name, func(t *testing.T) {
- agg := maxOverTimeAggregator{}
- for _, u := range tt.updates {
- agg.Update(u.value, u.timestamp, u.additionalInformation)
- }
- got := agg.Value()
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("got = %v, want %v", got, tt.want)
- }
- })
- }
- }
|