Fix a warning under aggregation
[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 local our $fake_handler = \42;
13
14 {
15     package TestFastCGIScript;
16     use Moose;
17     use namespace::autoclean;
18
19     extends 'Catalyst::Script::FastCGI';
20
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 };
26
27     __PACKAGE__->meta->make_immutable;
28 }
29
30 sub testOption {
31     my ($argstring, $resultarray) = @_;
32
33     local @ARGV = @$argstring;
34     local @TestAppToTestScripts::RUN_ARGS;
35     lives_ok {
36         TestFastCGIScript->new_with_options(application_name => 'TestAppToTestScripts')->run;
37     } "new_with_options";
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";
43 }
44
45 # Returns the hash expected when no flags are passed
46 sub opthash {
47     return {
48         (map { ($_ => undef) } qw(pidfile keep_stderr detach nproc manager)),
49         proc_title => 'perl-fcgi-pm [TestAppToTestScripts]',
50         @_,
51     };
52 }
53
54
55 # Test default (no opts/args behaviour)
56 testOption( [ qw// ], [undef, opthash()] );
57
58 # listen socket
59 testOption( [ qw|-l /tmp/foo| ], ['/tmp/foo', opthash()] );
60 testOption( [ qw/-l 127.0.0.1:3000/ ], ['127.0.0.1:3000', opthash()] );
61
62 #daemonize           -d --daemon
63 testOption( [ qw/-d/ ], [undef, opthash(detach => 1)] );
64 testOption( [ qw/--daemon/ ], [undef, opthash(detach => 1)] );
65
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')] );
70
71 # manager
72 testOption( [ qw/--manager foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
73 testOption( [ qw/-M foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
74
75 # keeperr
76 testOption( [ qw/--keeperr/ ], [undef, opthash(keep_stderr => 1)] );
77 testOption( [ qw/-e/ ], [undef, opthash(keep_stderr => 1)] );
78
79 # nproc
80 testOption( [ qw/--nproc 6/ ], [undef, opthash(nproc => 6)] );
81 testOption( [ qw/--n 6/ ], [undef, opthash(nproc => 6)] );
82
83 # proc_title
84 testOption( [ qw/--proc_title foo/ ], [undef, opthash(proc_title => 'foo')] );
85
86 done_testing;