/
30-examples-gradual.t
130 lines (108 loc) · 3.35 KB
/
30-examples-gradual.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use v6.c;
use Test;
use Bailador::Test;
plan 9;
chdir 'examples/gradual';
%*ENV<P6W_CONTAINER> = 'Bailador::Test';
%*ENV<BAILADOR_APP_ROOT> = $*CWD.absolute;
my $app = EVALFILE "app.pl6";
# test 1
if $*DISTRO.is-win {
skip "Skipping failing Windows test...";
}
else {
subtest {
plan 3;
my %data = run-psgi-request($app, 'GET', '/');
my $html = %data<response>[2];
%data<response>[2] = '';
is-deeply %data<response>, [200, ["Content-Type" => "text/html"], ''], 'route GET /';
is %data<err>, '';
like $html, rx:s/\<h1\>Main page \- from template\.\<\/h1\>/;
}, '/';
}
subtest {
plan 2;
my %data = run-psgi-request($app, 'GET', '/foo');
is-deeply %data<response>, [200, ["Content-Type" => "text/html"], 'Foo from route'], 'route GET /';
is %data<err>, '';
}, '/foo';
# test 3
if $*DISTRO.is-win {
skip "Skipping failing Windows test...";
}
else {
subtest {
plan 2;
my %data = run-psgi-request($app, 'GET', '/bar');
is-deeply %data<response>, [200, ["Content-Type" => "text/html"], "Bar from template\n"], 'route GET /bar';
is %data<err>, '';
}, '/bar';
}
subtest {
plan 2;
my %data = run-psgi-request($app, 'GET', '/qux');
is-deeply %data<response>, [200, ["Content-Type" => "text/html"], "Qux from route"], 'route GET /qux';
is %data<err>, '';
}, '/qux';
subtest {
plan 4;
my %data = run-psgi-request($app, 'GET', '/xyz');
is %data<response>[0], 404;
is-deeply %data<response>[1], ["Content-Type" => "text/plain;charset=UTF-8"];
is-deeply %data<response>[2], 'Not found';
is %data<err>, '', 'stderr';
}, '/xyz';
subtest {
plan 4;
my %data = run-psgi-request($app, 'GET', '/robots.txt');
is %data<response>[0], 200;
is-deeply %data<response>[1], ["Content-Type" => "text/plain;charset=UTF-8"];
is %data<response>[2].decode('utf-8'), "Disallow: /media/*\n";
is %data<err>, '', 'stderr';
}, '/xyz';
# test 7
if $*DISTRO.is-win {
skip "Skipping failing Windows test...";
}
else {
subtest {
plan 2;
my %data = run-psgi-request($app, 'GET', '/cakes/carrot');
is-deeply %data<response>, [200, ["Content-Type" => "text/html"], "Carrot Cake\n"], 'route GET /cakes/carrot';
is %data<err>, '';
}
}
# test 8
if $*DISTRO.is-win {
skip "Skipping failing Windows test...";
}
else {
subtest {
plan 2;
my %data = run-psgi-request($app, 'GET', '/cakes/');
is-deeply %data<response>, [200, ["Content-Type" => "text/html"], "Root Cake\n"], 'route GET /cakes/';
is %data<err>, '';
};
}
subtest {
plan 2 + 7;
my %data = run-psgi-request($app, 'GET', '/sitemap.xml');
my $html = %data<response>[2];
%data<response>[2] = '';
is-deeply %data<response>, [200, ["Content-Type" => "text/xml"], ''], 'route GET /sitemap.xml';
is %data<err>, '';
for (
'<?xml version="1.0" encoding="UTF-8"?>',
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
'<loc>http://0.0.0.0:1234/bar.html</loc>',
'<loc>http://0.0.0.0:1234/foo.html</loc>',
'<loc>http://0.0.0.0:1234/</loc>',
'<loc>http://0.0.0.0:1234/cakes/carrot.html</loc>',
'<loc>http://0.0.0.0:1234/cakes/</loc>',
) -> $url {
ok $html.index($url) > -1, $url;
}
};
# vim: expandtab
# vim: tabstop=4