Commit | Line | Data |
78dc94f2 |
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 | |
665a72a2 |
12 | local 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 | |
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; |
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 |
53 | sub 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) |
63 | testOption( [ qw// ], [undef, opthash()] ); |
64 | |
65 | # listen socket |
66 | testOption( [ qw|-l /tmp/foo| ], ['/tmp/foo', opthash()] ); |
67 | testOption( [ qw/-l 127.0.0.1:3000/ ], ['127.0.0.1:3000', opthash()] ); |
68 | |
69 | #daemonize -d --daemon |
e1d59dc4 |
70 | testOption( [ qw/-d/ ], [undef, opthash(detach => 1)] ); |
71 | testOption( [ qw/--daemon/ ], [undef, opthash(detach => 1)] ); |
78dc94f2 |
72 | |
ad08ab75 |
73 | # pidfile -pidfile -p --pid --pidfile |
78dc94f2 |
74 | testOption( [ qw/--pidfile cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] ); |
75 | testOption( [ qw/--pid cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] ); |
ad08ab75 |
76 | testOption( [ qw/-p cat.pid/ ], [undef, opthash(pidfile => 'cat.pid')] ); |
78dc94f2 |
77 | |
78 | # manager |
79 | testOption( [ qw/--manager foo::bar/ ], [undef, opthash(manager => 'foo::bar')] ); |
80 | testOption( [ qw/-M foo::bar/ ], [undef, opthash(manager => 'foo::bar')] ); |
81 | |
82 | # keeperr |
83 | testOption( [ qw/--keeperr/ ], [undef, opthash(keep_stderr => 1)] ); |
84 | testOption( [ qw/-e/ ], [undef, opthash(keep_stderr => 1)] ); |
85 | |
86 | # nproc |
87 | testOption( [ qw/--nproc 6/ ], [undef, opthash(nproc => 6)] ); |
88 | testOption( [ qw/--n 6/ ], [undef, opthash(nproc => 6)] ); |
89 | |
8865ee12 |
90 | # proc_title |
91 | testOption( [ qw/--proc_title foo/ ], [undef, opthash(proc_title => 'foo')] ); |
9c74923d |
92 | |
78dc94f2 |
93 | done_testing; |