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