source: mp3-find/trunk/t/04-new-db.t @ 34

Last change on this file since 34 was 34, checked in by peter, 16 years ago
  • added tests for the new database methods
  • updated docs for DB.pm
  • added new test file to the MANIFEST
  • updated public changelog (Changes)
File size: 1.4 KB
Line 
1#!/usr/bin/perl -w
2use strict;
3
4use Test::More;
5
6BEGIN {
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
17plan tests => 7;
18
19my $SEARCH_DIR = 't/mp3s';
20my $DB_FILE = 't/mp3.db';
21my $DSN = "dbi:SQLite:dbname=$DB_FILE";
22my $MP3_COUNT = 1;
23
24# exercise the object using the new methods ("create", "update", "sync")
25
26my $finder = MP3::Find::DB->new(
27    status_callback => sub {},  # be quiet about updates
28);
29isa_ok($finder, 'MP3::Find::DB');
30
31eval { $finder->create  };
32ok($@, 'create dies when not given a database name');
33eval { $finder->update  };
34ok($@, 'update dies when not given a database name');
35
36
37# create a test db
38unlink $DB_FILE;
39$finder->create({ dsn => $DSN });
40ok(-e $DB_FILE, 'db file is there');
41
42my $count = $finder->update({ dsn => $DSN, dirs => $SEARCH_DIR });
43is($count, $MP3_COUNT, 'added all the mp3s to the db');
44
45$count = $finder->sync({ dsn => $DSN });
46is($count, 0, 'sync works properly');
47
48# remove the db
49$finder->destroy_db($DB_FILE);
50ok(!-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
Note: See TracBrowser for help on using the repository browser.