[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 | |
---|
[19] | 25 | my $finder = MP3::Find::DB->new( |
---|
| 26 | status_callback => sub {}, # be quiet about updates |
---|
| 27 | ); |
---|
[10] | 28 | isa_ok($finder, 'MP3::Find::DB'); |
---|
| 29 | |
---|
| 30 | eval { $finder->create_db() }; |
---|
| 31 | ok($@, 'create_db dies when not given a database name'); |
---|
| 32 | eval { $finder->update_db() }; |
---|
| 33 | ok($@, 'update_db dies when not given a database name'); |
---|
| 34 | eval { $finder->destroy_db() }; |
---|
| 35 | ok($@, 'destroy_db dies when not given a database name'); |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | # create a test db |
---|
| 39 | unlink $DB_FILE; |
---|
| 40 | $finder->create_db($DB_FILE); |
---|
| 41 | ok(-e $DB_FILE, 'db file is there'); |
---|
| 42 | |
---|
| 43 | my $count = $finder->update_db($DB_FILE, $SEARCH_DIR); |
---|
| 44 | is($count, $MP3_COUNT, 'added all the mp3s to the db'); |
---|
| 45 | |
---|
| 46 | # remove the db |
---|
| 47 | $finder->destroy_db($DB_FILE); |
---|
| 48 | ok(!-e $DB_FILE, 'db file is gone'); |
---|
| 49 | |
---|
| 50 | #TODO: get some test mp3s |
---|
| 51 | #TODO: write a set of common set of test querys and counts for all the backends |
---|