File: load-from-app.t

package info (click to toggle)
libjson-validator-perl 5.14%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,160 kB
  • sloc: perl: 3,015; makefile: 14
file content (35 lines) | stat: -rw-r--r-- 1,132 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
use Mojo::Base -strict;
use JSON::Validator;
use Mojolicious;
use Test::More;

my $jv = JSON::Validator->new;
$jv->ua->server->app(Mojolicious->new);
$jv->ua->server->app->log(Mojo::Log->new->level('fatal'));
$jv->ua->server->app->routes->get(
  '/spec' => sub {
    my $c = shift;
    die 'not cached' if $c->stash('from_cache');
    $c->render(json => {'$ref' => 'http://swagger.io/v2/schema.json'});
  }
);

# Some CPAN testers says "Service Unavailable"
eval { $jv->schema('/spec') };
plan skip_all => $@ if $@ =~ /\bGET\b/i;

is $jv->store->ua,                         $jv->ua, 'shared ua';
is $@,                                     '',      'loaded schema from app';
is $jv->get('/properties/swagger/enum/0'), '2.0',   'loaded schema structure';

is_deeply [sort keys %{$jv->store->schemas}],
  ['/spec', 'http://json-schema.org/draft-04/schema', 'http://swagger.io/v2/schema.json'], 'schemas in store';

$jv->ua->server->app->defaults(from_cache => 1);
ok $jv->schema('/spec'), 'loaded from cache';

$jv->store->schemas({});
eval { $jv->schema('/spec') };
like $@, qr{Internal Server Error}, 'cache cleared';

done_testing;