PSGI, not Plack
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_script_fastcgi.t
CommitLineData
78dc94f2 1use strict;
2use warnings;
3
4use FindBin qw/$Bin/;
5use lib "$Bin/../lib";
6
7use Test::More;
8use Test::Exception;
9
10use Catalyst::Script::FastCGI;
11
12my $testopts;
13
14# Test default (no opts/args behaviour)
15testOption( [ qw// ], [undef, opthash()] );
16
17# listen socket
18testOption( [ qw|-l /tmp/foo| ], ['/tmp/foo', opthash()] );
19testOption( [ qw/-l 127.0.0.1:3000/ ], ['127.0.0.1:3000', opthash()] );
20
21#daemonize -d --daemon
e1d59dc4 22testOption( [ qw/-d/ ], [undef, opthash(detach => 1)] );
23testOption( [ qw/--daemon/ ], [undef, opthash(detach => 1)] );
78dc94f2 24
ad08ab75 25# pidfile -pidfile -p --pid --pidfile
78dc94f2 26testOption( [ qw/--pidfile cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
27testOption( [ qw/--pid cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
ad08ab75 28testOption( [ qw/-p cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
78dc94f2 29
30# manager
31testOption( [ qw/--manager foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
32testOption( [ qw/-M foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
33
34# keeperr
35testOption( [ qw/--keeperr/ ], [undef, opthash(keep_stderr => 1)] );
36testOption( [ qw/-e/ ], [undef, opthash(keep_stderr => 1)] );
37
38# nproc
39testOption( [ qw/--nproc 6/ ], [undef, opthash(nproc => 6)] );
40testOption( [ qw/--n 6/ ], [undef, opthash(nproc => 6)] );
41
8865ee12 42# proc_title
43testOption( [ qw/--proc_title foo/ ], [undef, opthash(proc_title => 'foo')] );
9c74923d 44
78dc94f2 45done_testing;
46
47sub testOption {
48 my ($argstring, $resultarray) = @_;
49
6ec45f37 50 local @ARGV = @$argstring;
51 local @TestAppToTestScripts::RUN_ARGS;
52 lives_ok {
53 Catalyst::Script::FastCGI->new_with_options(application_name => 'TestAppToTestScripts')->run;
54 } "new_with_options";
55 # First element of RUN_ARGS will be the script name, which we don't care about
56 shift @TestAppToTestScripts::RUN_ARGS;
b17bc48c 57 my $server = pop @TestAppToTestScripts::RUN_ARGS;
58 like ref($server), qr/^Plack::Handler/, 'Is a Plack::Handler';
6ec45f37 59 is_deeply \@TestAppToTestScripts::RUN_ARGS, $resultarray, "is_deeply comparison";
78dc94f2 60}
61
62# Returns the hash expected when no flags are passed
63sub opthash {
64 return {
9c74923d 65 (map { ($_ => undef) } qw(pidfile keep_stderr detach nproc manager)),
182f8b1e 66 proc_title => 'perl-fcgi-pm [TestAppToTestScripts]',
78dc94f2 67 @_,
68 };
69}