Files
slacker-bot/slackerbot/internal/storage/storage_test.go
T
2026-11-01 13:01:54 -05:00

33 lines
1.2 KiB
Go

package storage
import (
"errors"
"testing"
)
func TestDriveMath(t *testing.T) {
d := DriveReport{Path: "/a", UsableMB: 100_000, CommittedMB: 90_000, BookedMB: 150_000}
if d.HeadroomMB() != 10_000 || !d.Overbooked() {
t.Fatalf("headroom %d overbooked %v", d.HeadroomMB(), d.Overbooked())
}
if Committed(5120, 8000) != 8000 || Committed(5120, 100) != 5120 {
t.Fatal("a home holds its guarantee or its real use, whichever is bigger")
}
drives := []DriveReport{d, {Path: "/b", UsableMB: 50_000, CommittedMB: 20_000}}
if got, _ := PickDrive(drives, 5120); got != "/b" {
t.Fatalf("should pick the drive with the most room, got %s", got)
}
if _, err := PickDrive(drives, 40_000); !errors.Is(err, ErrStorageFull) {
t.Fatal("a guarantee that fits nowhere should be rejected")
}
}
func TestParseQgroupShow(t *testing.T) {
out := "Qgroupid Referenced Exclusive Max referenced Max exclusive Path\n" +
"-------- ---------- --------- -------------- ------------- ----\n" +
"0/257 3221225472 3221225472 10737418240 none c-c07abc\n"
if mb, err := parseQgroupShow(out); err != nil || mb != 3072 {
t.Fatalf("got %d, %v", mb, err)
}
}