-
Notifications
You must be signed in to change notification settings - Fork 1
/
050-proxy.t
51 lines (36 loc) · 1.3 KB
/
050-proxy.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
#!perl6
use v6;
use Test;
use Test::Util::ServerPort;
use Lumberjack;
use Lumberjack::Dispatcher::Proxy;
use Lumberjack::Message::JSON;
use HTTP::Server::Tiny;
my $port = get-unused-port();
my @messages;
# This basically what the Application does, just don't want to redispatch;
my $p = start {
constant JSONMessage = ( Lumberjack::Message but Lumberjack::Message::JSON );
sub app(%env) {
is %env<REQUEST_METHOD>, 'POST', "request is a post";
my $c = %env<p6w.input>.list.map({ .decode }).join('');
ok $c.defined, "got some data";
my $mess = JSONMessage.from-json($c);
@messages.append: $mess;
return 200, [ Content-Type => 'application/json' ], [ '{ "status" : "OK" }' ];
}
my $s = HTTP::Server::Tiny.new(:$port);
$s.run(&app);
};
class Foo does Lumberjack::Logger {
}
Foo.log-level = Lumberjack::All;
my $d;
lives-ok { $d = Lumberjack::Dispatcher::Proxy.new(url => "http://localhost:$port/") }, "create dispatcher";
Lumberjack.dispatchers.append: $d;
Foo.new.log-debug("test message");
is @messages.elems, 1, "got the message in the receiver";
isa-ok @messages[0], Lumberjack::Message, "got the message";
is @messages[0].message, "test message", "and it appears to be the right one";
done-testing;
# vim: expandtab shiftwidth=4 ft=perl6