Unit test to exercise streaming plack app mounting people/mattp/plack-streaming
Matt Phillips [Fri, 2 Nov 2012 14:34:16 +0000 (10:34 -0400)]
W::S doesn't do the right thing currently when a coderef returning coderef is
returned via a streaming plack app. This unit test exercises expected behavior.

t/dispatch_misc.t

index 0c11f2c..90c90ed 100644 (file)
@@ -22,6 +22,7 @@ sub run_request { $app->run_test_request( @_ ); }
 
 app_is_non_plack();
 plack_app_return();
+plack_streaming_app_return();
 broken_route_def();
 array_with_sub();
 array_with_no_sub();
@@ -68,6 +69,34 @@ sub plack_app_return {
       "when a route returns a thing that look like a Plack app, the web app redispatches to that thing";
 }
 
+sub plack_streaming_app_return {
+    {
+
+        package FauxPlackStreamApp;
+        sub new { bless {}, $_[0] }
+
+        sub to_app {
+            return sub {
+                return sub {
+                    my $responder = shift;
+                    $responder->([ 999, [], ["foo"] ]);
+                };
+            };
+        }
+    }
+
+    @dispatch = (
+        sub (/) {
+            FauxPlackStreamApp->new;
+        }
+    );
+
+    my $get = run_request( GET => 'http://localhost/' );
+
+    cmp_ok $get->code, '==', 999,
+      "when a route returns a thing that look like a Plack Streaming app, the web app redispatches to that thing";
+}
+
 sub broken_route_def {
 
     @dispatch = ( '/' => "" );