fix: nil slice -> empty slice in list API responses

Backend:
- ListStorageJobs, ListSambaShares, ListNFSExports, ListUsers,
  ListDirty, ListApplyLog, ListWatchedMounts: initialize with
  make([]T, 0) instead of var x []T to avoid JSON null on empty.
  Fixes "Cannot read properties of null" crash on /storage.

Frontend:
- Storage.tsx: defensive setJobs(res.jobs ?? []) to guard against
  API returning null.

Tests:
- Add TestListStorageJobsEmptyReturnsSlice.

Version: 0.7.1
This commit is contained in:
2026-07-06 23:31:03 -04:00
parent 27a52d2986
commit d3d59b4e45
9 changed files with 37 additions and 9 deletions
+27
View File
@@ -0,0 +1,27 @@
package db
import (
"testing"
)
func TestListStorageJobsEmptyReturnsSlice(t *testing.T) {
d, err := Open(":memory:")
if err != nil {
t.Fatalf("open db: %v", err)
}
defer d.Close()
if err := d.Migrate(); err != nil {
t.Fatalf("migrate: %v", err)
}
jobs, err := d.ListStorageJobs(50)
if err != nil {
t.Fatalf("ListStorageJobs: %v", err)
}
if jobs == nil {
t.Error("ListStorageJobs returned nil, want empty slice")
}
if len(jobs) != 0 {
t.Errorf("len(jobs) = %d, want 0", len(jobs))
}
}