Files
seaweedfs/weed/command/mount_common_test.go
T
Chris Lu 292145303f mount: name the disk without changing what is mounted (#11114)
mount: name the disk after the mount point when the whole tree is mounted

The mounted path was the only thing that named the disk, so a mount of the
whole tree was labelled with the filer address and the only way to give it
a name was to mount a subtree under that name — which hides everything
outside it. Fall back to the mount point's own name first, so
-dir=\\seaweedfs\Images labels the disk while -filer.path stays "/".

Claude-Session: https://claude.ai/code/session_01Q9f8pWBXu1ceJvcQfYRQ7x
2026-09-02 21:36:40 -07:00

89 lines
2.6 KiB
Go

//go:build linux || darwin || freebsd || windows
package command
import "testing"
func Test_volumeName(t *testing.T) {
tests := []struct {
name string
filer string
filerMountRootPath string
dir string
expected string
}{
{
name: "a drive letter leaves only the filer to fall back on",
filer: "127.0.0.1:8888",
filerMountRootPath: "/",
dir: "S:",
expected: "127.0.0.1:8888",
},
{
name: "empty path falls back to the filer",
filer: "127.0.0.1:8888",
filerMountRootPath: "",
expected: "127.0.0.1:8888",
},
{
name: "several filers stay parseable as one option",
filer: "127.0.0.1:8888,127.0.0.1:8889",
filerMountRootPath: "/",
expected: "127.0.0.1:8888+127.0.0.1:8889",
},
{
name: "a whole-tree mount takes the name of its network share",
filer: "127.0.0.1:8888",
filerMountRootPath: "/",
dir: `\\seaweedfs\Images`,
expected: "Images",
},
{
name: "a whole-tree mount takes the name of its directory",
filer: "127.0.0.1:8888",
filerMountRootPath: "/",
dir: "/mnt/seaweedfs",
expected: "seaweedfs",
},
{
name: "the mounted path outranks the mount point",
filer: "127.0.0.1:8888",
filerMountRootPath: "/buckets/videos",
dir: "/mnt/seaweedfs",
expected: "videos",
},
{
name: "a relative mount point is not a name",
filer: "127.0.0.1:8888",
filerMountRootPath: "/",
dir: ".",
expected: "127.0.0.1:8888",
},
{
name: "mounted directory names the disk",
filer: "127.0.0.1:8888",
filerMountRootPath: "/buckets/images",
expected: "images",
},
{
name: "trailing slash is not a name",
filer: "127.0.0.1:8888",
filerMountRootPath: "/buckets/videos/",
expected: "videos",
},
{
name: "spaces are kept, commas are not",
filer: "127.0.0.1:8888",
filerMountRootPath: "/Image, Disk",
expected: "Image+ Disk",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := volumeName(tt.filer, tt.filerMountRootPath, tt.dir); got != tt.expected {
t.Errorf("volumeName(%q, %q, %q) = %q, want %q", tt.filer, tt.filerMountRootPath, tt.dir, got, tt.expected)
}
})
}
}