Skip to content
Browse files

tests added

  • Loading branch information...
1 parent de3ce6a commit 646cc36fc2c7503b71a49b901dfc662749a857bb @gedarling committed May 20, 2011
Showing with 69 additions and 0 deletions.
  1. +69 −0 t/basic.t
View
69 t/basic.t
@@ -0,0 +1,69 @@
+use strict;
+use Plack::Test;
+use Test::More;
+use Test::Deep;
+use lib 'lib';
+use Plack::Middleware::LogWarn;
+use HTTP::Request::Common;
+
+my $basic_warn;
+
+my $app = sub {
+ my $env = shift;
+
+ #make the logger dump everything into our test var
+ local $env->{'psgix.logger'} = sub {
+ $basic_warn = shift;
+ };
+ #warn out something important to be logged
+ warn 'a voice crying out in the wilderness';
+
+ return [ 200, [], [] ];
+};
+
+#wrap with the default config
+$app = Plack::Middleware::LogWarn->wrap($app);
+
+test_psgi $app, sub {
+ my $cb = shift;
+ my $res = $cb->(GET "/");
+
+ my $expected = {
+ level => 'warn',
+ message => re('a voice crying out in the wilderness'),
+ };
+
+ cmp_deeply (
+ $basic_warn,
+ $expected,
+ 'warnings correct with default config'
+ );
+};
+
+my $configured_warn;
+
+my $configured_app = sub {
+ my $env = shift;
+
+ #make the logger dump everything into our test var
+ local $env->{'psgix.logger'} = sub {
+ $configured_warn = shift;
+ };
+
+ #warn out something important to be logged
+ warn 'a prophet is not welcomed in his own country';
+
+ return [ 200, [], [] ];
+};
+
+#wrap with a different logger (route to a var)
+$configured_app = Plack::Middleware::LogWarn->wrap($configured_app, logger => sub { $configured_warn = shift });
+
+test_psgi $configured_app, sub {
+ my $cb = shift;
+ my $res = $cb->(GET "/");
+
+ like $configured_warn, qr[a prophet is not welcomed in his own country], 'warnings correct with custom logger';
+};
+
+done_testing;

0 comments on commit 646cc36

Please sign in to comment.
Something went wrong with that request. Please try again.