File: 05dirs.t

package info (click to toggle)
libcatalyst-plugin-static-simple-perl 0.36-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 384 kB
  • sloc: perl: 2,629; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,393 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!perl

use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/lib";

use Test::More tests => 13;
use Catalyst::Test 'TestApp';

# test defined static dirs
TestApp->config->{'Plugin::Static::Simple'}->{dirs} = [
    'always-static',
    qr/^images/,
    'qr/^css/',
];

# a file with no extension will return text/plain
ok( my $res = request('http://localhost/always-static/test'), 'request ok' );
is( $res->content_type, 'text/plain', 'text/plain ok' );

# a file with an extension in ignore_extensions still gets served
ok( $res = request('http://localhost/always-static/test.html'), 'request ok' );
is( $res->code, 200, 'html file in dirs get served' );

# a missing file in a defined static dir will return 404 and text/html
ok( $res = request('http://localhost/always-static/404.txt'), 'request ok' );
is( $res->code, 404, '404 ok' );
is( $res->content_type, 'text/html', '404 is text/html' );

# qr regex test
ok( $res = request('http://localhost/images/catalyst.png'), 'request ok' );
like( $res->content_type, qr{\Aimage/.*png\z}, 'qr regex path ok' );

# eval regex test
ok( $res = request('http://localhost/css/static.css'), 'request ok' );
like( $res->content, qr/background/, 'eval regex path ok' );

# A static dir with no trailing slash is handled by Cat
ok( $res = request('http://localhost/always-static'), 'request ok' );
is( $res->content, 'default', 'content ok' );