-
Notifications
You must be signed in to change notification settings - Fork 574
/
json_config_lite_app.t
53 lines (39 loc) · 1.1 KB
/
json_config_lite_app.t
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
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env perl
# Copyright (C) 2008-2010, Sebastian Riedel.
use strict;
use warnings;
use File::Temp;
use Mojo::IOLoop;
use Test::More;
# Use a clean temporary directory
BEGIN { $ENV{MOJO_TMPDIR} ||= File::Temp::tempdir }
# Make sure sockets are working
plan skip_all => 'working sockets required for this test!'
unless Mojo::IOLoop->new->generate_port;
plan tests => 7;
# Oh, I always feared he might run off like this.
# Why, why, why didn't I break his legs?
use FindBin;
use Mojolicious::Lite;
use Test::Mojo;
# Silence
app->log->level('error');
# Load plugin
my $config =
plugin json_config => {default => {foo => 'baz', hello => 'there'}};
is($config->{foo}, 'bar');
is($config->{hello}, 'there');
# GET /
get '/' => 'index';
my $t = Test::Mojo->new;
# GET /
$t->get_ok('/')->status_is(200)->content_like(qr/bar/);
# No config file, default only
$config =
plugin json_config => {file => 'nonexisted', default => {foo => 'qux'}};
is($config->{foo}, 'qux');
# No config file, no default
ok(not eval { plugin json_config => {file => 'nonexisted'}; });
__DATA__
@@ index.html.ep
<%= $config->{foo} %>