From: Graham Knop Date: Fri, 19 Jun 2020 20:35:26 +0000 (+0200) Subject: convert test checking middleware set in config to setting middleware in plugin X-Git-Tag: v5.90_127~10^2~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=a21b003477f442246a2e68d0d4ec8267332b09bf;hp=479ca942e35e0764d3a48d4e49da4cc8c33133f8 convert test checking middleware set in config to setting middleware in plugin The issue that the test was checking was if a plugin could set up middleware. It was using an external plugin for this, but we can trivially include a test plugin to check the same behavior. --- diff --git a/maint/Makefile.PL.include b/maint/Makefile.PL.include index 04e5a26..5b50f1f 100644 --- a/maint/Makefile.PL.include +++ b/maint/Makefile.PL.include @@ -9,8 +9,8 @@ manifest_include t => 'catalyst_130pix.gif'; manifest_include 't/conf' => 'extra.conf.in'; manifest_include 't/lib/TestContentNegotiation/share', 'file.txt'; manifest_include 't/lib/TestMiddleware/share' => qr/.*/; -manifest_include 't/lib/TestMiddlewareFromConfig/share' => qr/.*/; -manifest_include 't/lib/TestMiddlewareFromConfig' => 'testmiddlewarefromconfig.pl'; +manifest_include 't/lib/TestMiddlewareFromPlugin/share' => qr/.*/; +manifest_include 't/lib/TestMiddlewareFromPlugin' => 'testmiddlewarefromplugin.pl'; manifest_include t => qr/optional_apache-.*\.pl/; manifest_include t => 'optional_stress.json'; manifest_include t => 'something/Makefile.PL'; diff --git a/t/lib/TestMiddlewareFromConfig.pm b/t/lib/TestMiddlewareFromPlugin.pm similarity index 55% rename from t/lib/TestMiddlewareFromConfig.pm rename to t/lib/TestMiddlewareFromPlugin.pm index 4c0af79..ce95ee8 100644 --- a/t/lib/TestMiddlewareFromConfig.pm +++ b/t/lib/TestMiddlewareFromPlugin.pm @@ -1,10 +1,11 @@ -package TestMiddlewareFromConfig; +package TestMiddlewareFromPlugin; -use Catalyst qw/ConfigLoader/; +use Catalyst qw/+TestMiddlewareFromPlugin::SetMiddleware/; ## Proof this is good config -##__PACKAGE__->config( do TestMiddlewareFromConfig->path_to('testmiddlewarefromconfig.pl') ); +##__PACKAGE__->config( do TestMiddlewareFromConfig->path_to('testmiddlewarefromplugin.pl') ); __PACKAGE__->setup_middleware('Head'); __PACKAGE__->setup; +1; diff --git a/t/lib/TestMiddlewareFromConfig/Controller/Root.pm b/t/lib/TestMiddlewareFromPlugin/Controller/Root.pm similarity index 80% rename from t/lib/TestMiddlewareFromConfig/Controller/Root.pm rename to t/lib/TestMiddlewareFromPlugin/Controller/Root.pm index 27be020..4458017 100644 --- a/t/lib/TestMiddlewareFromConfig/Controller/Root.pm +++ b/t/lib/TestMiddlewareFromPlugin/Controller/Root.pm @@ -1,4 +1,4 @@ -package TestMiddlewareFromConfig::Controller::Root; +package TestMiddlewareFromPlugin::Controller::Root; use Moose; use MooseX::MethodAttributes; diff --git a/t/lib/TestMiddlewareFromConfig/Custom.pm b/t/lib/TestMiddlewareFromPlugin/Custom.pm similarity index 63% rename from t/lib/TestMiddlewareFromConfig/Custom.pm rename to t/lib/TestMiddlewareFromPlugin/Custom.pm index dde1613..0b89b59 100644 --- a/t/lib/TestMiddlewareFromConfig/Custom.pm +++ b/t/lib/TestMiddlewareFromPlugin/Custom.pm @@ -1,4 +1,4 @@ -package TestMiddlewareFromConfig::Custom; +package TestMiddlewareFromPlugin::Custom; use strict; use warnings; diff --git a/t/lib/TestMiddlewareFromPlugin/SetMiddleware.pm b/t/lib/TestMiddlewareFromPlugin/SetMiddleware.pm new file mode 100644 index 0000000..7bd32bb --- /dev/null +++ b/t/lib/TestMiddlewareFromPlugin/SetMiddleware.pm @@ -0,0 +1,15 @@ +package TestMiddlewareFromPlugin::SetMiddleware; +use strict; +use warnings; +use File::Spec; +use File::Basename (); + +my $config_path = File::Spec->catfile(File::Basename::dirname(__FILE__), 'testmiddlewarefromplugin.pl'); + +sub setup { + my $c = shift; + $c->config(do $config_path); + $c->next::method(@_); +} + +1; diff --git a/t/lib/TestMiddlewareFromConfig/share/static/forced.txt b/t/lib/TestMiddlewareFromPlugin/share/static/forced.txt similarity index 100% rename from t/lib/TestMiddlewareFromConfig/share/static/forced.txt rename to t/lib/TestMiddlewareFromPlugin/share/static/forced.txt diff --git a/t/lib/TestMiddlewareFromConfig/share/static/message.txt b/t/lib/TestMiddlewareFromPlugin/share/static/message.txt similarity index 100% rename from t/lib/TestMiddlewareFromConfig/share/static/message.txt rename to t/lib/TestMiddlewareFromPlugin/share/static/message.txt diff --git a/t/lib/TestMiddlewareFromConfig/share/static2/message2.txt b/t/lib/TestMiddlewareFromPlugin/share/static2/message2.txt similarity index 100% rename from t/lib/TestMiddlewareFromConfig/share/static2/message2.txt rename to t/lib/TestMiddlewareFromPlugin/share/static2/message2.txt diff --git a/t/lib/TestMiddlewareFromConfig/share/static3/message3.txt b/t/lib/TestMiddlewareFromPlugin/share/static3/message3.txt similarity index 100% rename from t/lib/TestMiddlewareFromConfig/share/static3/message3.txt rename to t/lib/TestMiddlewareFromPlugin/share/static3/message3.txt diff --git a/t/lib/TestMiddlewareFromConfig/testmiddlewarefromconfig.pl b/t/lib/TestMiddlewareFromPlugin/testmiddlewarefromplugin.pl similarity index 74% rename from t/lib/TestMiddlewareFromConfig/testmiddlewarefromconfig.pl rename to t/lib/TestMiddlewareFromPlugin/testmiddlewarefromplugin.pl index d470f04..b6efd1a 100644 --- a/t/lib/TestMiddlewareFromConfig/testmiddlewarefromconfig.pl +++ b/t/lib/TestMiddlewareFromPlugin/testmiddlewarefromplugin.pl @@ -1,21 +1,21 @@ use Plack::Middleware::Static; my $static = Plack::Middleware::Static->new( - path => qr{^/static/}, root => TestMiddlewareFromConfig->path_to('share')); + path => qr{^/static/}, root => TestMiddlewareFromPlugin->path_to('share')); my $conf = +{ 'Controller::Root', { namespace => '' }, 'psgi_middleware', [ $static, - 'Static', { path => qr{^/static2/}, root => TestMiddlewareFromConfig->path_to('share') }, + 'Static', { path => qr{^/static2/}, root => TestMiddlewareFromPlugin->path_to('share') }, 'Runtime', - '+TestMiddleware::Custom', { path => qr{^/static3/}, root => TestMiddlewareFromConfig->path_to('share') }, + '+TestMiddleware::Custom', { path => qr{^/static3/}, root => TestMiddlewareFromPlugin->path_to('share') }, sub { my $app = shift; return sub { my $env = shift; if($env->{PATH_INFO} =~m/forced/) { - Plack::App::File->new(file=>TestMiddlewareFromConfig->path_to(qw/share static forced.txt/)) + Plack::App::File->new(file=>TestMiddlewareFromPlugin->path_to(qw/share static forced.txt/)) ->call($env); } else { return $app->($env); diff --git a/t/plack-middleware-config.t b/t/plack-middleware-plugin.t old mode 100644 new mode 100755 similarity index 87% rename from t/plack-middleware-config.t rename to t/plack-middleware-plugin.t index 728bff6..e2d7bcb --- a/t/plack-middleware-config.t +++ b/t/plack-middleware-plugin.t @@ -7,11 +7,8 @@ use FindBin; use Test::More; use HTTP::Request::Common; -BEGIN { eval { require Catalyst::Plugin::ConfigLoader; 1; } || - plan skip_all => 'Need Catalyst::Plugin::ConfigLoader' } - use lib "$FindBin::Bin/lib"; -use Catalyst::Test 'TestMiddlewareFromConfig'; +use Catalyst::Test 'TestMiddlewareFromPlugin'; ok my($res, $c) = ctx_request('/');