Add persistent thresholds and seven-day metrics history
This commit is contained in:
31
store_test.go
Normal file
31
store_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestStoreSettingsAndHistory(t *testing.T) {
|
||||
store, err := openStore(":memory:")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
|
||||
thresholds := defaultThresholds()
|
||||
thresholds.CPUWarning = 70
|
||||
if err := store.SaveThresholds(thresholds); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if loaded := store.Thresholds(); loaded.CPUWarning != 70 {
|
||||
t.Fatalf("настройки не сохранились: %+v", loaded)
|
||||
}
|
||||
|
||||
if err := store.AddHistory(HistoryPoint{Timestamp: time.Now().Unix(), CPUUsage: 42}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
points, err := store.History(1)
|
||||
if err != nil || len(points) != 1 || points[0].CPUUsage != 42 {
|
||||
t.Fatalf("история не сохранилась: points=%+v err=%v", points, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user