### ----------------------------------------------------
### -- Humming-Bird
### -- Licenses: MIT
### -- Authors: Rawley Fowler
### -- File: t/opt/plugin-dbiish.rakutest
### ----------------------------------------------------
use v6;
use lib 'lib';
use Test;
use Humming-Bird::Core;
use Humming-Bird::Glue;
use Humming-Bird::Backend;
use Humming-Bird::Middleware;
use Humming-Bird::Advice;

my \DBIish = try "use DBIish; DBIish".EVAL;

plan 9;

if DBIish ~~ Nil {
    skip-rest;
    exit;
}

class TestBackend does Humming-Bird::Backend {
    method listen(&handler) {
        return; # Does nothing
    }
}

use-ok "Humming-Bird::Plugin::DBIish", 'Does use ok? (not that you should :P)';
lives-ok sub { plugin('DBIish', ['TestMock']); }, 'Does default plugin not die?';
lives-ok sub { plugin('DBIish', 'other-db', ['TestMock']); }, 'Does other-db plugin not die?';
lives-ok sub { listen(8080, :backend(TestBackend)); }, 'Does plugin register ok?';
ok Humming-Bird::Glue::HTTPAction.^can('db'), 'Did plugin properly run?';
my $action = Humming-Bird::Glue::HTTPAction.new;
ok $action.^can('db')[0].($action), 'Is default DB accessible?';
ok $action.^can('db')[0].($action, 'other-db'), 'Is other db accessible?';
is $action.^can('db')[0].($action).^name.Str, "DBDish::TestMock::Connection", 'Is default db correct type?';
is $action.^can('db')[0].($action, 'other-db').^name.Str, "DBDish::TestMock::Connection", 'Is other db correct type?';

done-testing;


