Debian Codegraph @

t/issues/gh-730.t

raw
1 use strict;
2 use warnings;
3 use Test::More tests => 3;
4 use Plack::Test;
5 use HTTP::Request::Common;
6
7 {
8 package App;
9 use Dancer2;
10
11 get '/' => sub { request->is_behind_proxy };
12 }
13
14 my $app = App->to_app;
15 isa_ok( $app, 'CODE' );
16
17 my $test = Plack::Test->create($app);
18
19 subtest 'Runner config' => sub {
20 plan tests => 5;
21
22 is(
23 Dancer2->runner->config->{'behind_proxy'},
24 0,
25 'No default behind_proxy',
26 );
27
28 is(
29 scalar @{ Dancer2->runner->apps },
30 1,
31 'Single app registered',
32 );
33
34 isa_ok(
35 Dancer2->runner->apps->[0],
36 'Dancer2::Core::App',
37 'Correct app registered',
38 );
39
40 is(
41 Dancer2->runner->apps->[0]->setting('behind_proxy'),
42 0,
43 'behind_proxy not defined by default in an app',
44 );
45
46 Dancer2->runner->apps->[0]->config->{'behind_proxy'} = 1;
47
48 is(
49 Dancer2->runner->apps->[0]->setting('behind_proxy'),
50 1,
51 'Set behind_proxy locally in the app to one',
52 );
53
54 };
55
56 subtest 'Using App-level settings' => sub {
57 plan tests => 3;
58
59 is(
60 Dancer2->runner->config->{'behind_proxy'},
61 0,
62 'Runner\'s behind_proxy is still the default',
63 );
64
65 my $res = $test->request( GET '/' );
66 is( $res->code, 200, '[GET /] Correct code' );
67 is( $res->content, '1', '[GET /] Local value achieved' );
68 };
69