package backup import "testing" // TestTier2FitsHeadroom covers the size-aware rootfs-headroom guard that protects the ~8 GB guest // rootfs from being filled by a Tier 2 SSD copy (reserve = max(2 GB, 20% of total)). func TestTier2FitsHeadroom(t *testing.T) { cases := []struct { name string availGB, totalGB, unitGB float64 want bool }{ // 8 GB rootfs, ~2.4 GB free: a tiny unit fits (reserve = 2 GB), a 1 GB unit does NOT. {"8G rootfs, tiny unit fits", 2.4, 8.0, 0.02, true}, {"8G rootfs, 1G unit refused", 2.4, 8.0, 1.0, false}, {"8G rootfs, 0.3G unit fits", 2.4, 8.0, 0.3, true}, // Reserve is the larger of 2 GB and 20%: on 8 GB, 20% = 1.6 GB < 2 GB, so 2 GB applies. {"8G rootfs exactly at 2G reserve", 2.0, 8.0, 0.0, true}, {"8G rootfs just under reserve", 2.0, 8.0, 0.01, false}, // Large drive: 20% reserve dominates (204.8 GB on a 1 TB drive). {"1TB drive, 50G unit fits", 500.0, 1024.0, 50.0, true}, {"1TB drive, 320G unit refused (under 20% reserve)", 500.0, 1024.0, 320.0, false}, } for _, c := range cases { if got := tier2FitsHeadroom(c.availGB, c.totalGB, c.unitGB); got != c.want { t.Errorf("%s: tier2FitsHeadroom(avail=%.2f,total=%.2f,unit=%.2f)=%v want %v", c.name, c.availGB, c.totalGB, c.unitGB, got, c.want) } } }