Files
baby-nas/internal/storage/capabilities_test.go
T
darroyo 428056e1be feat: show disk usage of mover source with configurable warning threshold
GET /api/storage/disk-usage returns source path stats (total/used/free bytes, %).
Polls every 30s while Storage page is open.

Backend:
- migration 0009: adds mover_warning_threshold (1-99, default 80) to storage_config
- StatPath moved to internal/storage package for testability
- handleStorageDiskUsage returns {source: PathStat}

Frontend:
- DiskUsageBar component in Mergerfs Mover card: usage bar with color
  green < threshold, amber >= threshold, red >= 95%
- Warning message when threshold reached or exceeded
- New input in config form: Umbral de aviso (%)
- storageDiskUsage() API method

Tests: StatPath unit tests (empty/nonexistent/valid paths)

Version: 0.7.3
2026-07-07 00:30:32 -04:00

40 lines
1.0 KiB
Go

package storage
import "testing"
func TestStatPathEmpty(t *testing.T) {
out := StatPath("")
if out.Available {
t.Error("empty path: Available = true, want false")
}
if out.Error != "path no configurado" {
t.Errorf("empty path: Error = %q, want %q", out.Error, "path no configurado")
}
}
func TestStatPathNonexistent(t *testing.T) {
out := StatPath("/nonexistent/path/that/does/not/exist")
if out.Available {
t.Error("nonexistent path: Available = true, want false")
}
if out.Error == "" {
t.Error("nonexistent path: Error is empty, want non-empty")
}
}
func TestStatPathValid(t *testing.T) {
out := StatPath("/tmp")
if !out.Available {
t.Error("valid path /tmp: Available = false, want true")
}
if out.TotalBytes == 0 {
t.Error("valid path /tmp: TotalBytes = 0, want > 0")
}
if out.FreeBytes == 0 && out.UsedBytes == 0 {
t.Error("valid path /tmp: FreeBytes and UsedBytes both 0, unexpected")
}
if out.UsedPercent < 0 || out.UsedPercent > 100 {
t.Errorf("valid path /tmp: UsedPercent = %f, want 0-100", out.UsedPercent)
}
}