Don't import files if they don't have the supportted format extension,
[catagits/App-IdiotBox.git] / t / importer / video_files_from_dir.t
CommitLineData
625f105e 1use strict;
2use warnings FATAL => 'all';
3use autodie;
4
5use Test::More;
6
7use Cwd qw(getcwd);
8use File::Temp qw(tempdir);
9
10# Chdir to test directory for laziness
11my $original_dir = getcwd;
12END {
13 chdir $original_dir;
14}
15
16my $temp_dir = tempdir(CLEANUP => 1);
17chdir($temp_dir);
18
19use App::IdiotBox::Importer;
20
21my $method = 'video_files_from_dir';
22
23# No videos
24my $videos = App::IdiotBox::Importer->$method($temp_dir);
25is_deeply($videos, {}, 'No files reported from empty directory');
26
27# Unknown extensions
28open(undef, '>', 'fake.mp3');
29open(undef, '>', 'fake2.aac');
30
31$videos = App::IdiotBox::Importer->$method($temp_dir);
32is_deeply($videos, {}, 'No files reported from empty directory');
33
34# Known file types
35open(undef, '>', 'good.m4v');
36open(undef, '>', 'good2.flv');
37
38my $expect = {
39 'good' => [ 'm4v' ],
40 'good2' => [ 'flv' ],
41};
42
43$videos = App::IdiotBox::Importer->$method($temp_dir);
44is_deeply($videos, $expect, 'Known filetypes detected');
45
46# Grouping by file name without extension
47open(undef, '>', 'good.flv');
48
49unshift @{ $expect->{good} }, 'flv';
50
51$videos = App::IdiotBox::Importer->$method($temp_dir);
52is_deeply($videos, $expect, 'Known filetypes detected');
53
54done_testing;