Files
baby-nas/internal/modules/nfs/fsid_test.go
T
darroyo 65cd753818 feat: add storage info to settings page and improve NFS export handling
Backend:
- Add source/used_by/available/error fields to diskUsage in system status
- collectDiskUsage() now reads /proc/mounts, samba shares and NFS exports from DB
- Paths are deduplicated; shared paths list all shares/exports using them
- syscall.Statfs errors surface as available=false with user-facing error
- collectServiceStatus made a method of Server (receiver consistency)

Frontend:
- Settings page now shows two cards: mount points and shared resources
- Each path shows source badge (Sistema/Mount/SMB/NFS), used_by chips, progress bar
- Unavailable paths show amber warning instead of progress bar
- DiskUsage interface updated with new fields
- NFSExport interface updated with structured fields (fsid, async, etc)
- NFS page updated to use new export fields
2026-07-05 22:56:39 -04:00

57 lines
1009 B
Go

package nfs
import (
"sync"
"testing"
)
func TestUniqueFSIDNoCollision(t *testing.T) {
const goroutines = 100
results := make(chan uint32, goroutines)
var wg sync.WaitGroup
for i := 0; i < goroutines; i++ {
wg.Add(1)
go func() {
defer wg.Done()
n, err := generateRandomFSID()
if err != nil {
t.Errorf("generateRandomFSID failed: %v", err)
return
}
results <- n
}()
}
wg.Wait()
close(results)
seen := make(map[uint32]struct{})
for n := range results {
if _, dup := seen[n]; dup {
t.Errorf("duplicate fsid generated: %d", n)
}
seen[n] = struct{}{}
}
}
func TestUniqueFSIDWithUsedSet(t *testing.T) {
used := map[uint32]struct{}{
1: {}, 2: {}, 3: {},
}
for i := 0; i < 50; i++ {
n, err := UniqueFSID(used)
if err != nil {
t.Fatalf("UniqueFSID failed at iteration %d: %v", i, err)
}
if n == 0 {
t.Fatalf("fsid 0 is reserved")
}
if _, dup := used[n]; dup {
t.Fatalf("returned duplicate fsid: %d", n)
}
used[n] = struct{}{}
}
}