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

Last change on this file was 41, checked in by peter, 13 years ago

Fixed failing tests by correcting test plan numbers and moving the plan above the first use_ok call.

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    plan tests => 8;
15    use_ok('MP3::Find::DB')
16};
17
18my $SEARCH_DIR = 't/mp3s';
19my $DB_FILE = 't/mp3.db';
20my $DSN = "dbi:SQLite:dbname=$DB_FILE";
21my $MP3_COUNT = 1;
22
23# exercise the object using the new methods ("create", "update", "sync")
24
25my $finder = MP3::Find::DB->new(
26    status_callback => sub {},  # be quiet about updates
27);
28isa_ok($finder, 'MP3::Find::DB');
29
30eval { $finder->create  };
31ok($@, 'create dies when not given a database name');
32eval { $finder->update  };
33ok($@, 'update dies when not given a database name');
34
35
36# create a test db
37unlink $DB_FILE;
38$finder->create({ dsn => $DSN });
39ok(-e $DB_FILE, 'db file is there');
40
41my $count = $finder->update({ dsn => $DSN, dirs => $SEARCH_DIR });
42is($count, $MP3_COUNT, 'added all the mp3s to the db');
43
44$count = $finder->sync({ dsn => $DSN });
45is($count, 0, 'sync works properly');
46
47# remove the db
48$finder->destroy_db($DB_FILE);
49ok(!-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
Note: See TracBrowser for help on using the repository browser.