Store the script options in the engine.
[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
665a72a2 12local our $fake_handler = \42;
e40d69a7 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
30sub 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;
aee7cdcc 40
e40d69a7 41 my $server = pop @TestAppToTestScripts::RUN_ARGS;
42 is $server, $fake_handler, 'Loaded Plack handler gets passed to the app';
aee7cdcc 43
44 if (scalar(@TestAppToTestScripts::RUN_ARGS) && ref($TestAppToTestScripts::RUN_ARGS[-1]) eq "HASH") {
45 is ref(delete($TestAppToTestScripts::RUN_ARGS[-1]->{argv})), 'ARRAY';
46 is ref(delete($TestAppToTestScripts::RUN_ARGS[-1]->{extra_argv})), 'ARRAY';
47 }
48
e40d69a7 49 is_deeply \@TestAppToTestScripts::RUN_ARGS, $resultarray, "is_deeply comparison";
50}
51
52# Returns the hash expected when no flags are passed
53sub opthash {
54 return {
55 (map { ($_ => undef) } qw(pidfile keep_stderr detach nproc manager)),
56 proc_title => 'perl-fcgi-pm [TestAppToTestScripts]',
57 @_,
58 };
59}
60
78dc94f2 61
62# Test default (no opts/args behaviour)
63testOption( [ qw// ], [undef, opthash()] );
64
65# listen socket
66testOption( [ qw|-l /tmp/foo| ], ['/tmp/foo', opthash()] );
67testOption( [ qw/-l 127.0.0.1:3000/ ], ['127.0.0.1:3000', opthash()] );
68
69#daemonize -d --daemon
e1d59dc4 70testOption( [ qw/-d/ ], [undef, opthash(detach => 1)] );
71testOption( [ qw/--daemon/ ], [undef, opthash(detach => 1)] );
78dc94f2 72
ad08ab75 73# pidfile -pidfile -p --pid --pidfile
78dc94f2 74testOption( [ qw/--pidfile cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
75testOption( [ qw/--pid cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
ad08ab75 76testOption( [ qw/-p cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
78dc94f2 77
78# manager
79testOption( [ qw/--manager foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
80testOption( [ qw/-M foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
81
82# keeperr
83testOption( [ qw/--keeperr/ ], [undef, opthash(keep_stderr => 1)] );
84testOption( [ qw/-e/ ], [undef, opthash(keep_stderr => 1)] );
85
86# nproc
87testOption( [ qw/--nproc 6/ ], [undef, opthash(nproc => 6)] );
88testOption( [ qw/--n 6/ ], [undef, opthash(nproc => 6)] );
89
8865ee12 90# proc_title
91testOption( [ qw/--proc_title foo/ ], [undef, opthash(proc_title => 'foo')] );
9c74923d 92
78dc94f2 93done_testing;