#!perl

use Test::More tests => 3;
use Dancer::Plugin::Database;

my $opt  = { dsn => "dbi:SQLite:dbname=:memory:",
        dbi_params => {
            HandleError => sub { return 0 }, # gobble connect failed message
            RaiseError => 0,
            PrintError => 0,
        },
    };

my $handle;

$handle = database($opt);
ok($handle, "got handle for an in-memory database");

$opt->{dsn} = "dbi:SQLite:dbname=/Please/Tell/Me/This/File/Does/Not/Exist!",
my $opt2;
%$opt2 = %$opt;

$handle = database($opt2);
ok(!$handle, "no handle returned for a nonexistent database");

TODO: {
    local $TODO = "broken indexing of cached database handles";
    $handle = database($opt);
    ok(!$handle, "no cached handle returned for a nonexistent database");
}
