[10] | 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 | use_ok('MP3::Find::DB') |
---|
| 15 | }; |
---|
| 16 | |
---|
| 17 | plan tests => 7; |
---|
| 18 | |
---|
| 19 | my $SEARCH_DIR = 't/mp3s'; |
---|
| 20 | my $DB_FILE = 't/mp3.db'; |
---|
[12] | 21 | my $MP3_COUNT = 1; |
---|
[10] | 22 | |
---|
| 23 | # exercise the object |
---|
| 24 | |
---|
| 25 | my $finder = MP3::Find::DB->new; |
---|
| 26 | isa_ok($finder, 'MP3::Find::DB'); |
---|
| 27 | |
---|
| 28 | eval { $finder->create_db() }; |
---|
| 29 | ok($@, 'create_db dies when not given a database name'); |
---|
| 30 | eval { $finder->update_db() }; |
---|
| 31 | ok($@, 'update_db dies when not given a database name'); |
---|
| 32 | eval { $finder->destroy_db() }; |
---|
| 33 | ok($@, 'destroy_db dies when not given a database name'); |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | # create a test db |
---|
| 37 | unlink $DB_FILE; |
---|
| 38 | $finder->create_db($DB_FILE); |
---|
| 39 | ok(-e $DB_FILE, 'db file is there'); |
---|
| 40 | |
---|
| 41 | my $count = $finder->update_db($DB_FILE, $SEARCH_DIR); |
---|
| 42 | is($count, $MP3_COUNT, 'added all the mp3s to the db'); |
---|
| 43 | |
---|
| 44 | # remove the db |
---|
| 45 | $finder->destroy_db($DB_FILE); |
---|
| 46 | ok(!-e $DB_FILE, 'db file is gone'); |
---|
| 47 | |
---|
| 48 | #TODO: get some test mp3s |
---|
| 49 | #TODO: write a set of common set of test querys and counts for all the backends |
---|