1 | #!/usr/bin/perl -w |
---|
2 | use strict; |
---|
3 | |
---|
4 | use Test::More; |
---|
5 | |
---|
6 | BEGIN { |
---|
7 | eval { require DBI }; |
---|
8 | plan skip_all => 'DBI required to use MP3::Find::DB backend' if $@; |
---|
9 | eval { require DBD::SQLite }; |
---|
10 | plan skip_all => 'DBD::SQLite required to use MP3::Find::DB backend' if $@; |
---|
11 | eval { require SQL::Abstract }; |
---|
12 | plan skip_all => 'SQL::Abstract required to use MP3::Find::DB backend' if $@; |
---|
13 | |
---|
14 | plan tests => 8; |
---|
15 | use_ok('MP3::Find::DB') |
---|
16 | }; |
---|
17 | |
---|
18 | my $SEARCH_DIR = 't/mp3s'; |
---|
19 | my $DB_FILE = 't/mp3.db'; |
---|
20 | my $MP3_COUNT = 1; |
---|
21 | |
---|
22 | # exercise the object |
---|
23 | |
---|
24 | my $finder = MP3::Find::DB->new( |
---|
25 | status_callback => sub {}, # be quiet about updates |
---|
26 | ); |
---|
27 | isa_ok($finder, 'MP3::Find::DB'); |
---|
28 | |
---|
29 | eval { $finder->create_db() }; |
---|
30 | ok($@, 'create_db dies when not given a database name'); |
---|
31 | eval { $finder->update_db() }; |
---|
32 | ok($@, 'update_db dies when not given a database name'); |
---|
33 | eval { $finder->destroy_db() }; |
---|
34 | ok($@, 'destroy_db dies when not given a database name'); |
---|
35 | |
---|
36 | |
---|
37 | # create a test db |
---|
38 | unlink $DB_FILE; |
---|
39 | $finder->create_db($DB_FILE); |
---|
40 | ok(-e $DB_FILE, 'db file is there'); |
---|
41 | |
---|
42 | my $count = $finder->update_db($DB_FILE, $SEARCH_DIR); |
---|
43 | is($count, $MP3_COUNT, 'added all the mp3s to the db'); |
---|
44 | |
---|
45 | # remove the db |
---|
46 | $finder->destroy_db($DB_FILE); |
---|
47 | ok(!-e $DB_FILE, 'db file is gone'); |
---|
48 | |
---|
49 | #TODO: get some test mp3s |
---|
50 | #TODO: write a set of common set of test querys and counts for all the backends |
---|