package partition import "testing" func TestFreeBytesReturnsNonZeroOnTempDir(t *testing.T) { b, err := FreeBytes(t.TempDir()) if err != nil { t.Fatalf("FreeBytes: %v", err) } // On any sane test runner the temp filesystem has more than 1 KiB free. if b < 1024 { t.Errorf("FreeBytes = %d, want > 1024 on /tmp", b) } } func TestFreeBytesNonExistentPath(t *testing.T) { _, err := FreeBytes("/this/path/does/not/exist/at/all") if err == nil { t.Error("expected error for missing path, got nil") } } func TestHasFreeSpaceForRejectsHugeRequest(t *testing.T) { // Request 1 PiB with 10% headroom on /tmp — no test runner has that // much free, so this should consistently report not-enough. avail, ok, err := HasFreeSpaceFor(t.TempDir(), 1<<50, 10) if err != nil { t.Fatalf("HasFreeSpaceFor: %v", err) } if ok { t.Errorf("expected insufficient space for 1PiB, got avail=%d ok=true", avail) } } func TestHasFreeSpaceForAcceptsSmallRequest(t *testing.T) { // 1 KiB with 10% headroom = 1.1 KiB. Any temp dir has this. _, ok, err := HasFreeSpaceFor(t.TempDir(), 1024, 10) if err != nil { t.Fatalf("HasFreeSpaceFor: %v", err) } if !ok { t.Error("expected sufficient space for 1KiB on /tmp") } }