package library import "testing" // The video kinds share their extensions and differ only in how they group and // which kind they store. Those two facts are what let a movies library and a TV // library behave differently without the scanner knowing either name. func TestVideoKindsGroupAndStoreCorrectly(t *testing.T) { tests := []struct { kind string wantGroup GroupMode wantItem string }{ {"movies", GroupByFile, "video"}, {"tv", GroupByEpisode, "video"}, {"video", GroupByEpisode, "video"}, {"adult", GroupByFile, "video"}, {"hentai", GroupByEpisode, "video"}, // Every other media type stores its own kind, which is what they all // did before the video kinds were split. {"music", GroupByDirectory, "music"}, {"ebooks", GroupByFile, "ebooks"}, {"audiobooks", GroupByDirectory, "audiobooks"}, } for _, tt := range tests { if got := GroupModeFor(tt.kind); got != tt.wantGroup { t.Errorf("GroupModeFor(%q) = %q, want %q", tt.kind, got, tt.wantGroup) } if got := ItemKindFor(tt.kind); got != tt.wantItem { t.Errorf("ItemKindFor(%q) = %q, want %q", tt.kind, got, tt.wantItem) } } } // Every video kind owns the same containers. They are separated by how their // files become items, never by what they can hold. func TestVideoKindsShareTheirExtensions(t *testing.T) { want := ExtensionsFor("video") if len(want) == 0 { t.Fatal("the video kind owns no extensions") } for _, kind := range []string{"movies", "tv", "adult", "hentai"} { got := ExtensionsFor(kind) for ext := range want { if !got[ext] { t.Errorf("%s does not own %s, but every video kind should", kind, ext) } } } } // A kind nobody registered is still described by what is already on the row, so // a library created before a kind existed keeps working. func TestItemKindForUnregisteredKind(t *testing.T) { if got := ItemKindFor("nonsense"); got != "nonsense" { t.Errorf("ItemKindFor(nonsense) = %q, want nonsense", got) } }