46 lines
1.2 KiB
Go
46 lines
1.2 KiB
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)
|
|
}
|
|
}
|
|
|
|
func TestEntityHistory(t *testing.T) {
|
|
store, err := openStore(":memory:")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer store.Close()
|
|
value := 42.5
|
|
store.AddEntityHistory("zfs", "rpool", time.Now().Unix(), &value, nil)
|
|
series, err := store.EntityHistory("zfs", 24)
|
|
if err != nil || len(series) != 1 || len(series[0].Points) != 1 || series[0].Name != "rpool" {
|
|
t.Fatalf("unexpected entity history: %+v %v", series, err)
|
|
}
|
|
}
|