| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- package aggregator
- import (
- "reflect"
- "testing"
- "time"
- )
- func TestIncreaseAggregator_Value(t *testing.T) {
- time1 := time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)
- time2 := time.Date(2025, 1, 1, 0, 15, 0, 0, time.UTC)
- time3 := time.Date(2025, 1, 1, 0, 30, 0, 0, time.UTC)
- time4 := time.Date(2025, 1, 1, 0, 45, 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: 0,
- },
- },
- },
- "normal increase": {
- updates: []update{
- {
- value: 1,
- timestamp: time1,
- },
- {
- value: 2,
- timestamp: time2,
- },
- },
- want: []MetricValue{
- {
- Value: 1,
- },
- },
- },
- "double increase": {
- updates: []update{
- {
- value: 1,
- timestamp: time1,
- },
- {
- value: 2,
- timestamp: time1,
- },
- {
- value: 3,
- timestamp: time2,
- },
- {
- value: 4,
- timestamp: time2,
- },
- },
- want: []MetricValue{
- {
- Value: 4,
- },
- },
- },
- "set restart": {
- updates: []update{
- {
- value: 3,
- timestamp: time1,
- },
- {
- value: 4,
- timestamp: time2,
- },
- {
- value: 1,
- timestamp: time3,
- },
- {
- value: 2,
- timestamp: time4,
- },
- },
- want: []MetricValue{
- {
- Value: 2,
- },
- },
- },
- }
- for name, tt := range tests {
- t.Run(name, func(t *testing.T) {
- agg := increaseAggregator{}
- for _, u := range tt.updates {
- agg.Update(u.value, u.timestamp, u.additionalInformation)
- }
- got := agg.Value()
- if !reflect.DeepEqual(got, tt.want) {
- t.Errorf("IncreaseAggregator.Value() = %v, want %v", got, tt.want)
- }
- })
- }
- }
|