Clarify wording
[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;
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
46sub opthash {
47 return {
48 (map { ($_ => undef) } qw(pidfile keep_stderr detach nproc manager)),
49 proc_title => 'perl-fcgi-pm [TestAppToTestScripts]',
50 @_,
51 };
52}
53
78dc94f2 54
55# Test default (no opts/args behaviour)
56testOption( [ qw// ], [undef, opthash()] );
57
58# listen socket
59testOption( [ qw|-l /tmp/foo| ], ['/tmp/foo', opthash()] );
60testOption( [ qw/-l 127.0.0.1:3000/ ], ['127.0.0.1:3000', opthash()] );
61
62#daemonize -d --daemon
e1d59dc4 63testOption( [ qw/-d/ ], [undef, opthash(detach => 1)] );
64testOption( [ qw/--daemon/ ], [undef, opthash(detach => 1)] );
78dc94f2 65
ad08ab75 66# pidfile -pidfile -p --pid --pidfile
78dc94f2 67testOption( [ qw/--pidfile cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
68testOption( [ qw/--pid cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
ad08ab75 69testOption( [ qw/-p cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] );
78dc94f2 70
71# manager
72testOption( [ qw/--manager foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
73testOption( [ qw/-M foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
74
75# keeperr
76testOption( [ qw/--keeperr/ ], [undef, opthash(keep_stderr => 1)] );
77testOption( [ qw/-e/ ], [undef, opthash(keep_stderr => 1)] );
78
79# nproc
80testOption( [ qw/--nproc 6/ ], [undef, opthash(nproc => 6)] );
81testOption( [ qw/--n 6/ ], [undef, opthash(nproc => 6)] );
82
8865ee12 83# proc_title
84testOption( [ qw/--proc_title foo/ ], [undef, opthash(proc_title => 'foo')] );
9c74923d 85
78dc94f2 86done_testing;