-
Notifications
You must be signed in to change notification settings - Fork 574
/
embedded_lite_app.t
58 lines (41 loc) · 1.26 KB
/
embedded_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
54
55
56
57
58
#!/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 => 6;
# I heard you went off and became a rich doctor.
# I've performed a few mercy killings.
package EmbeddedTestApp;
use Mojolicious::Lite;
# Silence
app->log->level('error');
# GET /hello (embedded)
get '/hello' => sub {
my $self = shift;
my $name = $self->stash('name');
$self->render_text("Hello from the $name app!");
};
package main;
use Mojolicious::Lite;
use Test::Mojo;
# Silence
app->log->level('error');
# GET /hello
get '/hello' => sub { shift->render_text('Hello from the main app!') };
# /hello/* (dispatch to embedded app)
app->routes->route('/hello/(*path)')
->to(app => EmbeddedTestApp::app(), name => 'embedded');
my $t = Test::Mojo->new;
# GET /hello (from main app)
$t->get_ok('/hello')->status_is(200)->content_is('Hello from the main app!');
# GET /hello (from embedded app)
$t->get_ok('/hello/hello')->status_is(200)
->content_is('Hello from the embedded app!');