65cd753818
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
155 lines
3.3 KiB
Go
155 lines
3.3 KiB
Go
package importer
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseExports(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
wantLen int
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "basic export",
|
|
input: `/srv/nfs/shared 192.168.1.0/24(rw,sync,no_subtree_check)
|
|
`,
|
|
wantLen: 1,
|
|
},
|
|
{
|
|
name: "multiple clients same path",
|
|
input: `/srv/nfs/shared *(ro,sync) 192.168.1.0/24(rw,sync,no_root_squash)
|
|
`,
|
|
wantLen: 1,
|
|
},
|
|
{
|
|
name: "multiple exports",
|
|
input: `# This is a comment
|
|
/srv/nfs/data 192.168.1.0/24(rw,sync)
|
|
/srv/nfs/public *(ro,sync)
|
|
|
|
# another comment
|
|
/srv/nfs/backup 10.0.0.0/8(ro,sync,no_subtree_check)
|
|
`,
|
|
wantLen: 3,
|
|
},
|
|
{
|
|
name: "wildcard client",
|
|
input: `/srv/nfs/public *(ro,sync,no_root_squash)
|
|
`,
|
|
wantLen: 1,
|
|
},
|
|
{
|
|
name: "wildcard client with parentheses",
|
|
input: `/srv/nfs/shared *(rw,sync,no_root_squash)
|
|
`,
|
|
wantLen: 1,
|
|
},
|
|
{
|
|
name: "empty input",
|
|
input: "",
|
|
wantLen: 0,
|
|
},
|
|
{
|
|
name: "only comments",
|
|
input: `# comment 1
|
|
# comment 2
|
|
`,
|
|
wantLen: 0,
|
|
},
|
|
{
|
|
name: "multiple spaces between entries",
|
|
input: `/srv/nfs/shared 192.168.1.0/24(rw,sync) 10.0.0.0/8(ro)
|
|
`,
|
|
wantLen: 1,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := parseExports([]byte(tt.input))
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("parseExports() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if len(got) != tt.wantLen {
|
|
t.Errorf("parseExports() got %d exports, want %d", len(got), tt.wantLen)
|
|
for i, e := range got {
|
|
t.Logf(" export[%d]: path=%q clients=%v fsid=%d", i, e.Path, e.Clients, e.FSID)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseExportLine(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
line string
|
|
wantPath string
|
|
wantCount int
|
|
}{
|
|
{
|
|
name: "single client with options",
|
|
line: `/srv/nfs/shared 192.168.1.100(rw,sync,no_subtree_check)`,
|
|
wantPath: `/srv/nfs/shared`,
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "wildcard with default options",
|
|
line: `/srv/nfs/public *(ro)`,
|
|
wantPath: `/srv/nfs/public`,
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "multiple clients",
|
|
line: `/srv/nfs/shared 192.168.1.0/24(rw) 10.0.0.0/8(ro)`,
|
|
wantPath: `/srv/nfs/shared`,
|
|
wantCount: 2,
|
|
},
|
|
{
|
|
name: "netgroup",
|
|
line: `/srv/nfs/shared @admins(rw,sync)`,
|
|
wantPath: `/srv/nfs/shared`,
|
|
wantCount: 1,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, ok := parseExportLine(tt.line)
|
|
if !ok {
|
|
t.Errorf("parseExportLine(%q) returned false", tt.line)
|
|
return
|
|
}
|
|
if got.Path != tt.wantPath {
|
|
t.Errorf("parseExportLine(%q) path = %q, want %q", tt.line, got.Path, tt.wantPath)
|
|
}
|
|
if len(got.Clients) != tt.wantCount {
|
|
t.Errorf("parseExportLine(%q) clients = %v, want %d", tt.line, got.Clients, tt.wantCount)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSplitExportsClients(t *testing.T) {
|
|
tests := []struct {
|
|
input string
|
|
expected []string
|
|
}{
|
|
{`192.168.1.0/24(rw,sync) 10.0.0.0/8(ro)`, []string{`192.168.1.0/24(rw,sync)`, `10.0.0.0/8(ro)`}},
|
|
{`*(ro)`, []string{`*(ro)`}},
|
|
{`192.168.1.100(rw)`, []string{`192.168.1.100(rw)`}},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.input, func(t *testing.T) {
|
|
got := splitExportsClients(tt.input)
|
|
if len(got) != len(tt.expected) {
|
|
t.Errorf("splitExportsClients(%q) = %v, want %v", tt.input, got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|