/
accesslog.t
92 lines (78 loc) · 2.14 KB
/
accesslog.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use v6;
use Test;
use Crust::Middleware::AccessLog;
use lib 't/lib/';
use SupplierBuffer;
my &hello-app = sub (%env) {
start { 404, [], ['hello'] }
}
sub make-check-combined-logs($buf) {
return sub {
my $s = $buf.result();
if ! ok($s.defined, "\$s is defined") {
note $s;
return;
}
ok $s ~~ /^ '127.0.0.1 - - [' /, "starts with 127.0.0.1";
my $v = $s.index('] "GET /apache_pb.gif HTTP/1.1" 404 - "http://www.example.com/start.html" "-"');
if ! ok($v.defined, "\$v is defined") {
note $s;
return;
}
ok($v > 0);
note "# " ~ $s if %*ENV<TEST_VERBOSE>;
}
}
sub runit (&app, &checker, %extra-env?) {
my %env = (
:REMOTE_ADDR<127.0.0.1>,
:HTTP_REFERER<http://www.example.com/start.html>,
:REQUEST_METHOD<GET>,
:REQUEST_URI</apache_pb.gif>,
:SERVER_PROTOCOL<HTTP/1.1>,
);
if %extra-env.defined {
%env = (|%env, |%extra-env);
}
await &app(%env);
&checker();
}
{
my $buf = SupplierBuffer.new;
my &code = Crust::Middleware::AccessLog.new(&hello-app);
runit(&code, make-check-combined-logs($buf), ("p6w.errors" => $buf.supplier));
}
{
my $buf = SupplierBuffer.new;
my &code = Crust::Middleware::AccessLog.new(
&hello-app,
format => "combined",
);
runit(&code, make-check-combined-logs($buf), ("p6w.errors" => $buf.supplier));
}
{
my $buf = SupplierBuffer.new;
my &code = Crust::Middleware::AccessLog.new(
&hello-app,
format => Nil,
);
runit(&code, make-check-combined-logs($buf), ("p6w.errors" => $buf.supplier));
}
{
my $buf = SupplierBuffer.new;
my &code = Crust::Middleware::AccessLog.new(
&hello-app,
format => "",
);
runit(&code, make-check-combined-logs($buf), ("p6w.errors" => $buf.supplier));
}
{
my $buf = SupplierBuffer.new;
my &code = Crust::Middleware::AccessLog.new(
&hello-app,
format => Nil,
logger => sub { my $s = shift @_; $buf.supplier.emit($s) },
);
runit(&code, make-check-combined-logs($buf));
}
done-testing;