gobbler/categorize/categorizer_test.go

54 lines
1.1 KiB
Go

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) {
outLocation, err := categorizer.CategorizeFile(test.fileName)
assert.Nil(t, err)
outPath, err := outLocation.Path()
assert.Nil(t, err)
assert.Equal(t, test.expectedPath, outPath)
})
}
}