package musicfs import ( "testing" "github.com/stretchr/testify/assert" ) func TestDeriveSubdir(t *testing.T) { tests := []struct { name string originRoot string contentPath string expected string }{ { name: "normal subdirectory", originRoot: "/downloads/music", contentPath: "/downloads/music/Metallica - Master of Puppets (1986) [FLAC]", expected: "Metallica - Master of Puppets (1986) [FLAC]", }, { name: "nested subdirectory", originRoot: "/downloads/music", contentPath: "/downloads/music/Metal/Metallica/Master of Puppets", expected: "Metal/Metallica/Master of Puppets", }, { name: "same directory", originRoot: "/downloads/music", contentPath: "/downloads/music", expected: ".", }, { name: "outside origin root falls back to empty", originRoot: "/downloads/music", contentPath: "/tmp/other/path", expected: "", }, { name: "parent directory falls back to empty", originRoot: "/downloads/music/sub", contentPath: "/downloads/music", expected: "", }, { name: "trailing slash on root", originRoot: "/downloads/music/", contentPath: "/downloads/music/Album", expected: "Album", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := DeriveSubdir(tt.originRoot, tt.contentPath) assert.Equal(t, tt.expected, result) }) } }