2021-08-30 03:20:38 +00:00
|
|
|
package categorize
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"testing/fstest"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func makeMapFSWithEmptyEntries(names ...string) fstest.MapFS {
|
|
|
|
mapFS := make(fstest.MapFS, len(names))
|
|
|
|
for _, name := range names {
|
|
|
|
mapFS[name] = &fstest.MapFile{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mapFS
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeTestCategorizer() Categorizer {
|
|
|
|
testFS := makeMapFSWithEmptyEntries("The-Simpsons", "Seinfeld", "Westworld", "Barry")
|
|
|
|
|
|
|
|
return newCategorizerForFS(testFS)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCategorizesTVShowFiles(t *testing.T) {
|
|
|
|
tt := []struct {
|
|
|
|
fileName string
|
|
|
|
expectedPath string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Westworld.S02.1080p.AMZN.WEB-DL.DDP5.1.H.264-NTb",
|
|
|
|
"Westworld/Season-2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Barry.S01E01.Chapter.One.Make.Your.Mark.1080p.AMZN.WEB-DL.DDP5.1.H.264-NTb.mkv",
|
|
|
|
"Barry/Season-1",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tt {
|
|
|
|
testName := fmt.Sprintf("%s to %s", test.fileName, test.expectedPath)
|
|
|
|
categorizer := makeTestCategorizer()
|
|
|
|
t.Run(testName, func(t *testing.T) {
|
2021-09-01 03:22:12 +00:00
|
|
|
outLocation, err := categorizer.CategorizeFile(test.fileName)
|
|
|
|
assert.Nil(t, err)
|
2021-08-30 03:20:38 +00:00
|
|
|
|
2021-09-01 03:22:12 +00:00
|
|
|
outPath, err := outLocation.Path()
|
2021-08-30 03:20:38 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, test.expectedPath, outPath)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|