Skip to content

Commit 6e61ba3

Browse files
committed
For [GH #124] [GH #117] - Simplify test for mount_psgi.
1 parent 7b68ecf commit 6e61ba3

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

t/psgi.t

+29-21
Original file line numberDiff line numberDiff line change
@@ -85,33 +85,41 @@ sub is_or_like($$;$) {
8585
} GET "/virt?foo=bar";
8686

8787
undef *test_action; # To free $site ref
88+
}
8889

89-
sub test_psgi (&@) {
90-
my ($subref, $request, %params) = @_;
91-
92-
my $path = $request->uri->path;
93-
94-
$site->mount_psgi($path => sub {$subref->(@_); [200, [], "OK"]});
90+
{
91+
# mount_psgi and PATH_INFO test.
92+
my $t = sub {
93+
my ($mount_path, $req_path, $want_pathinfo, $more_desc) = @_;
94+
95+
$site->mount_psgi(
96+
$mount_path,
97+
sub {
98+
my ($env) = @_;
99+
is $env->{PATH_INFO}, $want_pathinfo
100+
, "mount psgi $mount_path, GET $req_path => PT($want_pathinfo)"
101+
. ($more_desc // '')
102+
;
103+
[200, [], "OK"]
104+
}
105+
);
106+
107+
Plack::Test->create($app)->request(GET $req_path)
108+
};
95109

96-
$client->request($request, %params);
97-
}
110+
$t->("/mnt" => "/mnt" => ""
111+
, ": PT maybe '' for root");
98112

99-
test_psgi {
100-
(my Env $env) = @_;
101-
is $env->{PATH_INFO}, "/mpsgi", "mount psgi path_info";
102-
} GET "/mpsgi";
113+
$t->("/mnt" => "/mnt/" => "/"
114+
, ": Nonempty PT must start with /");
103115

104-
test_psgi {
105-
(my Env $env) = @_;
106-
is $env->{PATH_INFO}, "/mpsgi2", "mount psgi path_info, 2";
107-
} GET "/mpsgi2";
116+
$t->("/mnt/" => "/mnt/" => "/"
117+
, ": Last / in mount path is not trimmed from PT");
108118

109-
test_psgi {
110-
(my Env $env) = @_;
111-
is $env->{PATH_INFO}, "/mpsgi", "mount psgi path_info, overwritten";
112-
} GET "/mpsgi";
119+
$t->("/mnt2" => "/mnt2" => ""
120+
, ": mnt2, not mnt. Longest must win.");
121+
}
113122

114-
undef *test_psgi; # To free $site ref.
115123
}
116124

117125
my $hello = sub {

0 commit comments

Comments
 (0)