package disk import ( "testing" "time" ) func float(value float64) *float64 { return &value } func TestTemperatureHysteresisAndUnsupportedCapabilities(t *testing.T) { policy := PerformancePolicy{} if got := TemperatureStatus("normal", 52, policy); got != "attention" { t.Fatalf("got=%s", got) } if got := TemperatureStatus("attention", 48, policy); got != "attention" { t.Fatalf("got=%s", got) } if got := TemperatureStatus("attention", 44, policy); got != "normal" { t.Fatalf("got=%s", got) } spin, err := normalizeSpin(&RawSpin{Supported: false}) if err != nil || spin.State != "unsupported" { t.Fatalf("spin=%+v err=%v", spin, err) } performance, err := normalizePerformance(&RawPerformance{Available: false}, time.Now(), PerformancePolicy{}) if err != nil || performance.State != "unsupported" { t.Fatalf("performance=%+v err=%v", performance, err) } } func TestPerformanceHistoryIsBoundedAndSorted(t *testing.T) { now := time.Date(2026, 8, 1, 12, 0, 0, 0, time.UTC) old := now.Add(-time.Minute) newer := now.Add(-time.Second) raw := RawPerformance{Available: true, Current: RawPerformanceSample{ObservedAt: now, ReadBytesPerSecond: float(100)}, History: []RawPerformanceSample{{ObservedAt: old}, {ObservedAt: newer}}} got, err := normalizePerformance(&raw, now, PerformancePolicy{MaxHistory: 2}) if err != nil || got.State != "available" || len(got.History) != 2 || !got.History[0].ObservedAt.Equal(newer) { t.Fatalf("performance=%+v err=%v", got, err) } raw.History = append(raw.History, RawPerformanceSample{}) if _, err = normalizePerformance(&raw, now, PerformancePolicy{MaxHistory: 2}); err == nil { t.Fatal("expected history bounds error") } } func TestTemperatureObservationAndPerformanceValuesRejectInvalid(t *testing.T) { now := time.Date(2026, 8, 1, 12, 0, 0, 0, time.UTC) future := now.Add(2 * time.Hour) if _, err := normalizeTemperature(&RawTemperature{Available: true, Celsius: 52, ObservedAt: future}, now, PerformancePolicy{}); err == nil { t.Fatal("expected future temperature error") } if _, err := normalizePerformance(&RawPerformance{Available: true, Current: RawPerformanceSample{ObservedAt: now, ReadBytesPerSecond: float(-1)}}, now, PerformancePolicy{}); err == nil { t.Fatal("expected invalid performance error") } }