25 lines
673 B
Go
25 lines
673 B
Go
package store
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestTrimHistoryToMaxPoints(t *testing.T) {
|
|
s := &Store{}
|
|
base := time.Date(2026, 4, 20, 0, 0, 0, 0, time.UTC)
|
|
s.history = make([]Sample, 0, MaxHistoryPoints+25)
|
|
for i := 0; i < MaxHistoryPoints+25; i++ {
|
|
s.history = append(s.history, Sample{At: base.Add(time.Duration(i) * time.Second), Value: i})
|
|
}
|
|
|
|
s.trimHistoryLocked(base.Add(time.Duration(MaxHistoryPoints+25) * time.Second))
|
|
|
|
if got := len(s.history); got != MaxHistoryPoints {
|
|
t.Fatalf("history length = %d, want %d", got, MaxHistoryPoints)
|
|
}
|
|
if s.history[0].Value != 25 {
|
|
t.Fatalf("oldest retained value = %d, want %d", s.history[0].Value, 25)
|
|
}
|
|
}
|