### ----------------------------------------------------
### -- Humming-Bird
### -- Licenses: MIT
### -- Authors: Rawley Fowler
### -- File: t/13-plugin.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;

plan 8;

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

lives-ok sub { plugin('Config', 't/static/.humming-bird.json'); }, 'Does Config plugin not die?';
lives-ok sub { plugin 'Logger'; }, 'Does Logger plugin not die?';
lives-ok sub { plugin 'Session'; }, 'Does Session plugin not die?';
lives-ok sub { listen(8080, :backend(TestBackend)); }, 'Does plugin register ok?';
ok Humming-Bird::Glue::HTTPAction.^can('config'), 'Did plugin properly run?';

my $action = Humming-Bird::Glue::HTTPAction.new;

ok $action.config<database_url> eq 'foo', 'Did config parse properly?';
is middleware().elems, 2, 'Did logger properly setup middleware?';
is advice().elems, 2, 'Did logger properly setup advice?'; # This has to be 2 because of the identity function that implicity exists

done-testing;


