Last active
May 31, 2020 16:45
-
-
Save marcoarthur/577bc43806650ee756c27c2ddf2fa1f5 to your computer and use it in GitHub Desktop.
how to make a test file with two mojo applications (or how to subprocess one of it ?)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## no critic | |
package MyApp; | |
use Mojolicious::Lite; | |
get '/' => sub { shift->render( text => "MyApp running" ) }; | |
package YetApp; | |
use Mojolicious::Lite; | |
get '/' => sub { shift->render( text => "Yet App running" ) }; | |
helper proxy => sub { | |
my ($c, $url) = @_; | |
$c->ua->server->app(MyApp->new); # set the server for UA | |
return $c->ua->get($url)->res->body; | |
}; | |
package main; | |
## critic | |
use Test::Mojo; | |
use Test::More; | |
my $app = Test::Mojo->new('MyApp'); | |
my $yet = Test::Mojo->new('YetApp'); | |
sub test_indepent { | |
my ($app, $body) = @_; | |
$app->app->log->level('fatal'); | |
$app->get_ok('/')->status_is(200); | |
my $tx = $app->tx; | |
is $tx->res->body, $body, "Ok for $body"; | |
} | |
test_indepent($app, "MyApp running"); # OK | |
test_indepent($yet, "Yet App running"); # OK | |
is $yet->app->proxy('/'), "MyApp running", "OK proxy"; # OK | |
done_testing | |
__END__ | |
itaipu@ubatuba:~/projects/Mojo/Concepts/Sandbox$ prove -v | |
t/subprocess_mojo_app.t .. No subtests run | |
t/two_mojolite.t ......... | |
ok 1 - GET / | |
ok 2 - 200 OK | |
ok 3 - Ok for MyApp running | |
ok 4 - GET / | |
ok 5 - 200 OK | |
ok 6 - Ok for Yet App running | |
ok 7 - OK proxy | |
1..7 | |
ok | |
Test Summary Report | |
------------------- | |
t/subprocess_mojo_app.t (Wstat: 0 Tests: 0 Failed: 0) | |
Parse errors: No plan found in TAP output | |
Files=2, Tests=7, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.83 cusr 0.04 csys = 0.90 CPU) | |
Result: FAIL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment