|
| 1 | +// mem_test.go — contraste de memUsagePct con mediciones reales (issue #513). |
| 2 | +package adapters |
| 3 | + |
| 4 | +import "testing" |
| 5 | + |
| 6 | +func TestMemUsagePct(t *testing.T) { |
| 7 | + cases := []struct { |
| 8 | + name string |
| 9 | + total, free, buff, cach, av float64 |
| 10 | + want int |
| 11 | + }{ |
| 12 | + { |
| 13 | + // rt3 AX6 real: con Cached (fórmula clásica) baja del 79% al 67%. |
| 14 | + name: "rt3 con cached", total: 414264, free: 45780, buff: 0, cach: 90464, av: 88088, want: 67, |
| 15 | + }, |
| 16 | + { |
| 17 | + // Sin Cached (payload viejo/ubus): se mantiene el comportamiento |
| 18 | + // anterior basado en MemAvailable. |
| 19 | + name: "rt3 fallback available", total: 414264, free: 45780, buff: 0, cach: 0, av: 88088, want: 79, |
| 20 | + }, |
| 21 | + { |
| 22 | + // rt4 AX6: 60% con la fórmula previa; la clásica baja. |
| 23 | + name: "rt4 con cached", total: 414264, free: 120000, buff: 0, cach: 48876, av: 165268, want: 59, |
| 24 | + }, |
| 25 | + { |
| 26 | + // Sin available, cae a free+buffered. |
| 27 | + name: "sin available", total: 1000, free: 100, buff: 50, cach: 0, av: 0, want: 85, |
| 28 | + }, |
| 29 | + {name: "cached mayor que el resto", total: 100, free: 0, buff: 0, cach: 500, av: 0, want: 0}, |
| 30 | + {name: "total cero", total: 0, free: 0, buff: 0, cach: 0, av: 0, want: 0}, |
| 31 | + } |
| 32 | + for _, tc := range cases { |
| 33 | + got := memUsagePct(tc.total, tc.free, tc.buff, tc.cach, tc.av) |
| 34 | + if got != tc.want { |
| 35 | + t.Errorf("%s: got %d, want %d", tc.name, got, tc.want) |
| 36 | + } |
| 37 | + } |
| 38 | +} |
0 commit comments