use inlined module hiding in tests
[catagits/Catalyst-Runtime.git] / t / aggregate / live_priorities.t
1 use strict;
2 use warnings;
3
4 use FindBin;
5 use lib "$FindBin::Bin/../lib";
6
7 use Test::More tests => 14;
8 use Catalyst::Test 'TestApp';
9
10 local $^W = 0;
11
12 my $uri_base = 'http://localhost/priorities';
13 my @tests = (
14
15     #   Simple
16     'Local vs. Path 1',     { path => '/loc_vs_path1',   expect => 'local' },
17     'Local vs. Path 2',     { path => '/loc_vs_path2',   expect => 'path' },
18
19     #   index
20     'index vs. Local',      { path => '/loc_vs_index',   expect => 'index' },
21     'index vs. Path',       { path => '/path_vs_index',  expect => 'index' },
22
23     'multimethod zero',     { path => '/multimethod',    expect => 'zero' },
24     'multimethod one',      { path => '/multimethod/1',  expect => 'one 1' },
25     'multimethod two',      { path => '/multimethod/1/2',
26                                                          expect => 'two 1 2' },
27 );
28
29 while ( @tests ) {
30
31     my $name = shift @tests;
32     my $data = shift @tests;
33
34     #   Run tests for path with trailing slash and without
35   SKIP: for my $req_uri 
36     ( 
37         join( '' => $uri_base, $data->{ path } ),      # Without trailing path
38         join( '' => $uri_base, $data->{ path }, '/' ), # With trailing path
39     ) {
40         my $end_slash = ( $req_uri =~ qr(/$) ? 1 : 0 );
41
42         #   use slash_expect argument if URI ends with slash 
43         #   and the slash_expect argument is defined
44         my $expect = $data->{ expect } || '';
45         if ( $end_slash and exists $data->{ slash_expect } ) {
46             $expect = $data->{ slash_expect };
47         }
48
49         #   Call the URI on the TestApp
50         my $response = request( $req_uri );
51
52         #   Leave expect out to see the result
53         unless ( $expect ) {
54             skip 'Nothing expected, winner is ' . $response->content, 1;
55         }
56
57         #   Show error if response was no success
58         if ( not $response->is_success ) {
59             diag 'Error: ' . $response->headers->{ 'x-catalyst-error' };
60         }
61
62         #   Test if content matches expectations.
63         #   TODO This might flood the screen with the catalyst please-come-later
64         #        page. So I don't know it is a good idea.
65         is( $response->content, $expect,
66             "$name: @{[ $data->{ expect } ]} wins"
67             . ( $end_slash ? ' (trailing slash)' : '' )
68         );
69     }
70 }
71