convert test checking middleware set in config to setting middleware in plugin
Graham Knop [Fri, 19 Jun 2020 20:35:26 +0000 (22:35 +0200)]
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.

maint/Makefile.PL.include
t/lib/TestMiddlewareFromPlugin.pm [moved from t/lib/TestMiddlewareFromConfig.pm with 55% similarity]
t/lib/TestMiddlewareFromPlugin/Controller/Root.pm [moved from t/lib/TestMiddlewareFromConfig/Controller/Root.pm with 80% similarity]
t/lib/TestMiddlewareFromPlugin/Custom.pm [moved from t/lib/TestMiddlewareFromConfig/Custom.pm with 63% similarity]
t/lib/TestMiddlewareFromPlugin/SetMiddleware.pm [new file with mode: 0644]
t/lib/TestMiddlewareFromPlugin/share/static/forced.txt [moved from t/lib/TestMiddlewareFromConfig/share/static/forced.txt with 100% similarity]
t/lib/TestMiddlewareFromPlugin/share/static/message.txt [moved from t/lib/TestMiddlewareFromConfig/share/static/message.txt with 100% similarity]
t/lib/TestMiddlewareFromPlugin/share/static2/message2.txt [moved from t/lib/TestMiddlewareFromConfig/share/static2/message2.txt with 100% similarity]
t/lib/TestMiddlewareFromPlugin/share/static3/message3.txt [moved from t/lib/TestMiddlewareFromConfig/share/static3/message3.txt with 100% similarity]
t/lib/TestMiddlewareFromPlugin/testmiddlewarefromplugin.pl [moved from t/lib/TestMiddlewareFromConfig/testmiddlewarefromconfig.pl with 74% similarity]
t/plack-middleware-plugin.t [moved from t/plack-middleware-config.t with 87% similarity, mode: 0755]

index 04e5a26..5b50f1f 100644 (file)
@@ -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';
similarity index 55%
rename from t/lib/TestMiddlewareFromConfig.pm
rename to t/lib/TestMiddlewareFromPlugin.pm
index 4c0af79..ce95ee8 100644 (file)
@@ -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;
@@ -1,4 +1,4 @@
-package TestMiddlewareFromConfig::Controller::Root;
+package TestMiddlewareFromPlugin::Controller::Root;
 
 use Moose;
 use MooseX::MethodAttributes;
similarity index 63%
rename from t/lib/TestMiddlewareFromConfig/Custom.pm
rename to t/lib/TestMiddlewareFromPlugin/Custom.pm
index dde1613..0b89b59 100644 (file)
@@ -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 (file)
index 0000000..7bd32bb
--- /dev/null
@@ -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;
@@ -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);
old mode 100644 (file)
new mode 100755 (executable)
similarity index 87%
rename from t/plack-middleware-config.t
rename to t/plack-middleware-plugin.t
index 728bff6..e2d7bcb
@@ -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('/');