X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Faggregate%2Funit_core_script_fastcgi.t;h=93f1c16aa0cc31441ffb19bd4a2aac7a90e8d3f0;hp=27f245ac341cd1a1932de1cb7cc34e4d33921142;hb=aee7cdcc0b2b3b7dc672b4b4a31b8c3b7ef3f1f7;hpb=8865ee1205d2f74a601105ae6c85af2cceb8ad7d diff --git a/t/aggregate/unit_core_script_fastcgi.t b/t/aggregate/unit_core_script_fastcgi.t index 27f245a..93f1c16 100644 --- a/t/aggregate/unit_core_script_fastcgi.t +++ b/t/aggregate/unit_core_script_fastcgi.t @@ -9,7 +9,55 @@ use Test::Exception; use Catalyst::Script::FastCGI; -my $testopts; +local our $fake_handler = \42; + +{ + package TestFastCGIScript; + use Moose; + use namespace::autoclean; + + extends 'Catalyst::Script::FastCGI'; + + # Avoid loading the real plack engine, as that will load FCGI and fail if + # it's not there. We don't really need a full engine anyway as the overriden + # MyApp->run will just capture its arguments and return without delegating + # to the engine to run things. + override load_engine => sub { $fake_handler }; + + __PACKAGE__->meta->make_immutable; +} + +sub testOption { + my ($argstring, $resultarray) = @_; + + local @ARGV = @$argstring; + local @TestAppToTestScripts::RUN_ARGS; + lives_ok { + TestFastCGIScript->new_with_options(application_name => 'TestAppToTestScripts')->run; + } "new_with_options"; + # First element of RUN_ARGS will be the script name, which we don't care about + shift @TestAppToTestScripts::RUN_ARGS; + + my $server = pop @TestAppToTestScripts::RUN_ARGS; + is $server, $fake_handler, 'Loaded Plack handler gets passed to the app'; + + if (scalar(@TestAppToTestScripts::RUN_ARGS) && ref($TestAppToTestScripts::RUN_ARGS[-1]) eq "HASH") { + is ref(delete($TestAppToTestScripts::RUN_ARGS[-1]->{argv})), 'ARRAY'; + is ref(delete($TestAppToTestScripts::RUN_ARGS[-1]->{extra_argv})), 'ARRAY'; + } + + is_deeply \@TestAppToTestScripts::RUN_ARGS, $resultarray, "is_deeply comparison"; +} + +# Returns the hash expected when no flags are passed +sub opthash { + return { + (map { ($_ => undef) } qw(pidfile keep_stderr detach nproc manager)), + proc_title => 'perl-fcgi-pm [TestAppToTestScripts]', + @_, + }; +} + # Test default (no opts/args behaviour) testOption( [ qw// ], [undef, opthash()] ); @@ -43,29 +91,3 @@ testOption( [ qw/--n 6/ ], [undef, opthash(nproc => 6)] ); testOption( [ qw/--proc_title foo/ ], [undef, opthash(proc_title => 'foo')] ); done_testing; - -sub testOption { - my ($argstring, $resultarray) = @_; - - local @ARGV = @$argstring; - local @TestAppToTestScripts::RUN_ARGS; - lives_ok { - Catalyst::Script::FastCGI->new_with_options(application_name => 'TestAppToTestScripts')->run; - } "new_with_options"; - # First element of RUN_ARGS will be the script name, which we don't care about - shift @TestAppToTestScripts::RUN_ARGS; - is_deeply \@TestAppToTestScripts::RUN_ARGS, $resultarray, "is_deeply comparison"; -} - -# Returns the hash expected when no flags are passed -sub opthash { - return { - pidfile => undef, - keep_stderr => undef, - detach => undef, - nproc => undef, - manager => undef, - proc_title => undef, - @_, - }; -}