32 lines
775 B
Go
32 lines
775 B
Go
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)
|
|
}
|
|
}
|