Files
darroyo 0da789cd96 fix: populate fsid for legacy NFS exports on migration
Migration 0002 added fsid column with DEFAULT 0 but never
populated existing rows. Now PopulateLegacyFSIDs() runs after 0002
to extract fsid from legacy options string or generate random.

Also: move generateRandomFSID to internal/system to avoid import
cycles. Migration 0004 drops the legacy options column.

Version: 0.3.1 -> 0.3.2
2026-07-06 01:22:16 -04:00

59 lines
1.0 KiB
Go

package nfs
import (
"sync"
"testing"
"github.com/darroyo/nasctl/internal/system"
)
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 := system.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{}{}
}
}