10 use Catalyst::Script::FastCGI;
12 local our $fake_handler = \42;
15 package TestFastCGIScript;
17 use namespace::autoclean;
19 extends 'Catalyst::Script::FastCGI';
21 # Avoid loading the real plack engine, as that will load FCGI and fail if
22 # it's not there. We don't really need a full engine anyway as the overriden
23 # MyApp->run will just capture its arguments and return without delegating
24 # to the engine to run things.
25 override load_engine => sub { $fake_handler };
27 __PACKAGE__->meta->make_immutable;
31 my ($argstring, $resultarray) = @_;
33 local @ARGV = @$argstring;
34 local @TestAppToTestScripts::RUN_ARGS;
36 TestFastCGIScript->new_with_options(application_name => 'TestAppToTestScripts')->run;
38 # First element of RUN_ARGS will be the script name, which we don't care about
39 shift @TestAppToTestScripts::RUN_ARGS;
40 my $server = pop @TestAppToTestScripts::RUN_ARGS;
41 is $server, $fake_handler, 'Loaded Plack handler gets passed to the app';
42 is_deeply \@TestAppToTestScripts::RUN_ARGS, $resultarray, "is_deeply comparison";
45 # Returns the hash expected when no flags are passed
48 (map { ($_ => undef) } qw(pidfile keep_stderr detach nproc manager)),
49 proc_title => 'perl-fcgi-pm [TestAppToTestScripts]',
55 # Test default (no opts/args behaviour)
56 testOption( [ qw// ], [undef, opthash()] );
59 testOption( [ qw|-l /tmp/foo| ], ['/tmp/foo', opthash()] );
60 testOption( [ qw/-l 127.0.0.1:3000/ ], ['127.0.0.1:3000', opthash()] );
62 #daemonize -d --daemon
63 testOption( [ qw/-d/ ], [undef, opthash(detach => 1)] );
64 testOption( [ qw/--daemon/ ], [undef, opthash(detach => 1)] );
66 # pidfile -pidfile -p --pid --pidfile
67 testOption( [ qw/--pidfile cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
68 testOption( [ qw/--pid cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
69 testOption( [ qw/-p cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
72 testOption( [ qw/--manager foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
73 testOption( [ qw/-M foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
76 testOption( [ qw/--keeperr/ ], [undef, opthash(keep_stderr => 1)] );
77 testOption( [ qw/-e/ ], [undef, opthash(keep_stderr => 1)] );
80 testOption( [ qw/--nproc 6/ ], [undef, opthash(nproc => 6)] );
81 testOption( [ qw/--n 6/ ], [undef, opthash(nproc => 6)] );
84 testOption( [ qw/--proc_title foo/ ], [undef, opthash(proc_title => 'foo')] );