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