[34] | 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'; |
---|
| 21 | my $DSN = "dbi:SQLite:dbname=$DB_FILE"; |
---|
| 22 | my $MP3_COUNT = 1; |
---|
| 23 | |
---|
| 24 | # exercise the object using the new methods ("create", "update", "sync") |
---|
| 25 | |
---|
| 26 | my $finder = MP3::Find::DB->new( |
---|
| 27 | status_callback => sub {}, # be quiet about updates |
---|
| 28 | ); |
---|
| 29 | isa_ok($finder, 'MP3::Find::DB'); |
---|
| 30 | |
---|
| 31 | eval { $finder->create }; |
---|
| 32 | ok($@, 'create dies when not given a database name'); |
---|
| 33 | eval { $finder->update }; |
---|
| 34 | ok($@, 'update dies when not given a database name'); |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | # create a test db |
---|
| 38 | unlink $DB_FILE; |
---|
| 39 | $finder->create({ dsn => $DSN }); |
---|
| 40 | ok(-e $DB_FILE, 'db file is there'); |
---|
| 41 | |
---|
| 42 | my $count = $finder->update({ dsn => $DSN, dirs => $SEARCH_DIR }); |
---|
| 43 | is($count, $MP3_COUNT, 'added all the mp3s to the db'); |
---|
| 44 | |
---|
| 45 | $count = $finder->sync({ dsn => $DSN }); |
---|
| 46 | is($count, 0, 'sync works properly'); |
---|
| 47 | |
---|
| 48 | # remove the db |
---|
| 49 | $finder->destroy_db($DB_FILE); |
---|
| 50 | ok(!-e $DB_FILE, 'db file is gone'); |
---|
| 51 | |
---|
| 52 | #TODO: get some test mp3s |
---|
| 53 | #TODO: write a set of common set of test querys and counts for all the backends |
---|