AWS-Lambda
view release on metacpan or search on metacpan
t/20_psgi.t view on Meta::CPAN
use strict;
use warnings;
use utf8;
use Test::More;
use FindBin;
use JSON::XS qw/decode_json encode_json/;
use File::Slurp qw(slurp);
use Plack::Request;
use Test::Deep qw(cmp_deeply);
use Test::Warn;
use JSON::Types;
use Encode;
use AWS::Lambda::Context;
use AWS::Lambda::PSGI;
sub slurp_json {
my $name = $_[0];
return decode_json(slurp("$FindBin::Bin/$name"));
}
sub slurp_fh {
my $fh = shift;
my $data = "";
while ($fh->read(my $buf, 4096)) {
$data .= $buf;
}
return decode_utf8($data);
}
my $app = AWS::Lambda::PSGI->new;
subtest "API Gateway GET Request" => sub {
my $input = slurp_json("testdata/apigateway-get-request.json");
my $output = $app->format_input($input);
my $req = Plack::Request->new($output);
is $req->method, 'GET', 'method';
my $content;
warning_is { $content = slurp_fh($req->input) } undef, 'no warning';
is $content, '', 'content';
is $req->request_uri, '/foo%20/bar?query=hoge&query=fuga', 'request uri';
is $req->path_info, '/foo /bar', 'path info';
is $req->query_string, 'query=hoge&query=fuga', 'query string';
is $req->header('Header-Name'), 'Value1, Value2', 'header';
ok !$req->env->{'psgi.streaming'}, 'psgi.streaming';
};
subtest "API Gateway POST Request" => sub {
my $input = slurp_json("testdata/apigateway-post-request.json");
my $output = $app->format_input($input);
my $req = Plack::Request->new($output);
is $req->method, 'POST', 'method';
is $req->content_type, 'application/json', 'content-type';
my $content;
warning_is { $content = slurp_fh($req->input) } undef, 'no warning';
is $content, '{"hello":"ããã«ã¡ã¯ä¸ç"}', 'content';
is $req->request_uri, '/', 'request uri';
is $req->path_info, '/', 'path info';
is $req->query_string, '', 'query string';
ok !$req->env->{'psgi.streaming'}, 'psgi.streaming';
};
subtest "API Gateway Base64 encoded POST Request" => sub {
my $input = slurp_json("testdata/apigateway-base64-request.json");
my $output = $app->format_input($input);
my $req = Plack::Request->new($output);
( run in 2.202 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )