From 2388747fbf954de990862a6c01713d50823e8725 Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Tue, 24 Aug 2021 11:10:39 +0200 Subject: overhauled testing --- lib/JWebmail.pm | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'lib/JWebmail.pm') diff --git a/lib/JWebmail.pm b/lib/JWebmail.pm index dc68bd2..2c03d1b 100644 --- a/lib/JWebmail.pm +++ b/lib/JWebmail.pm @@ -5,41 +5,49 @@ use Mojo::Base 'Mojolicious'; use JWebmail::Controller::Webmail; use JWebmail::Model::ReadMails; use JWebmail::Model::Driver::QMailAuthuser; -use JWebmail::Model::Driver::Mock; use JWebmail::Model::WriteMails; +use JWebmail::Model::Driver::MockJSON; +use JWebmail::Model::Driver::MockMaildir; + sub startup { my $self = shift; $self->moniker('jwebmail'); + my $mode = $self->mode; + $self->log->path($self->home->child('log', "$mode.log")); + # load plugins push @{$self->plugins->namespaces}, 'JWebmail::Plugin'; $self->plugin('INIConfig'); $self->plugin('ServerSideSessionData'); $self->plugin('Helper'); - my $i18n_route = $self->plugin('I18N2', $self->config('i18n') // {}); + my $i18n_route = $self->plugin('I18N2', $self->config('i18n')); $self->secrets( [$self->config('secret')] ) if $self->config('secret'); delete $self->config->{secret}; # initialize models - $self->helper(users => sub { - state $x = JWebmail::Model::ReadMails->new( - driver => $self->config->{development}{use_read_mock} - ? JWebmail::Model::Driver::Mock->new() - : JWebmail::Model::Driver::QMailAuthuser->new( - logfile => $self->home->child('log', 'extract.log'), - %{ $self->config->{model}{read}{driver} // {} }, - ) - ); - }); + no warnings "experimental::smartmatch"; + my $driver = do { + given ($self->config->{development}{use_read_mock}) { + when (/^json/) { JWebmail::Model::Driver::MockJSON->new() } + when (/^maildir/) { JWebmail::Model::Driver::MockMaildir->new(extractor => 'rust') } + default { + JWebmail::Model::Driver::QMailAuthuser->new( + logfile => $self->home->child('log', 'extract.log'), + %{ $self->config->{model}{read}{driver} // {} }) + } + } + }; + my $read_mails = JWebmail::Model::ReadMails->new(driver => $driver); + $self->helper(users => sub { $read_mails }); $self->helper(send_mail => sub { my ($c, $mail) = @_; JWebmail::Model::WriteMails::sendmail($mail) }); $JWebmail::Model::WriteMails::Block_Writes = 1 if $self->config->{development}{block_writes}; - # add helper and stash values $self->defaults(version => __PACKAGE__->VERSION); $self->route($i18n_route); @@ -49,7 +57,7 @@ sub startup { sub route { my $self = shift; - my $r = shift || $self->routes; + my $r = shift // $self->routes; $r->get('/' => 'noaction')->to('Webmail#noaction'); $r->get('/about')->to('Webmail#about'); -- cgit v1.2.3