d3d59b4e45
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
28 lines
511 B
Go
28 lines
511 B
Go
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))
|
|
}
|
|
}
|