Basic tests for fcgi script
[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()] );
23 testOption( [ qw/--daemon/ ], [undef, opthash()] );
24
25 # pidfile        -pidfile                  --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
29 # manager
30 testOption( [ qw/--manager foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
31 testOption( [ qw/-M foo::bar/ ], [undef, opthash(manager => 'foo::bar')] );
32
33 # keeperr
34 testOption( [ qw/--keeperr/ ], [undef, opthash(keep_stderr => 1)] );
35 testOption( [ qw/-e/ ], [undef, opthash(keep_stderr => 1)] );
36
37 # nproc
38 testOption( [ qw/--nproc 6/ ], [undef, opthash(nproc => 6)] );
39 testOption( [ qw/--n 6/ ], [undef, opthash(nproc => 6)] );
40
41 # detach
42 testOption( [ qw/--detach/ ], [undef, opthash(detach => 1)] );
43 testOption( [ qw/--det/ ], [undef, opthash(detach => 1)] );
44
45 done_testing;
46
47 sub testOption {
48     my ($argstring, $resultarray) = @_;
49
50     subtest "Test for ARGV: @$argstring" => sub
51         {
52             plan tests => 2;
53             local @ARGV = @$argstring;
54             local @TestAppToTestScripts::RUN_ARGS;
55             lives_ok {
56                 Catalyst::Script::FastCGI->new_with_options(application_name => 'TestAppToTestScripts')->run;
57             } "new_with_options";
58             # First element of RUN_ARGS will be the script name, which we don't care about
59             shift @TestAppToTestScripts::RUN_ARGS;
60             is_deeply \@TestAppToTestScripts::RUN_ARGS, $resultarray, "is_deeply comparison";
61             done_testing;
62         };
63 }
64
65 # Returns the hash expected when no flags are passed
66 sub opthash {
67     return {
68         pidfile => undef,
69         keep_stderr => undef,
70         detach => undef,
71         nproc => undef,
72         manager => undef,
73         @_,
74     };
75 }