76e426c5d3
- Add internal/musicfs package: gRPC client, TriggerRescan (stream consumer), EnrichFiles (BatchUpdateMetadata), DeriveSubdir helper - Add MusicFS config section (enabled, endpoint, origin_id, origin_root, timeout) - Wire MusicFSClient into PollDownloadWorker: on download completion, trigger scoped rescan then push enriched metadata - Fix album auto-persist in monitor workflow: persist artist+album from metadata-agregator before saving torrent/download - Add filterByActiveSeeders: skip torrents where magnet resolution found 0 real active seeders - Add musicfs proto to buf.gen.yaml inputs - Enricher only sends non-empty fields to avoid overwriting existing file tag data with empty values
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
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)
|
|
})
|
|
}
|
|
}
|