Alien-Base-ModuleBuild
view release on metacpan or search on metacpan
t/alien_base_modulebuild_repository_http.t view on Meta::CPAN
{
my $uri = $repo->build_uri('http','host.com/', '/path/', 'http://host.com/other/file.ext');
is $uri, 'http://host.com/other/file.ext', 'absolute URI found in link';
}
{
my $uri = $repo->build_uri('http','host.com/', '/path/', 'http://example.org/other/file.ext');
is $uri, 'http://example.org/other/file.ext', 'absolute URI on different host';
}
{
my $uri = $repo->build_uri('https', 'github.com', '/libssh2/libssh2/releases/',
'/libssh2/libssh2/releases/download/libssh2-1.6.0/libssh2-1.6.0.tar.gz');
is $uri, 'https://github.com/libssh2/libssh2/releases/download/libssh2-1.6.0/libssh2-1.6.0.tar.gz';
}
};
subtest 'content disposition' => sub {
my $content_disposition;
my $mock = mock 'HTTP::Tiny' => (
override => [
mirror => sub {
my $response = { success => 1 };
$response->{headers}->{'content-disposition'} = $content_disposition
if defined $content_disposition;
$response;
},
],
);
my $repo = Alien::Base::ModuleBuild::Repository::HTTP->new(
host => 'foo.bar.com',
);
is(Alien::Base::ModuleBuild::File->new( repository => $repo, filename => 'bogus' )->get, 'bogus', 'no content disposition');
$content_disposition = 'attachment; filename=foo.txt';
is(Alien::Base::ModuleBuild::File->new( repository => $repo, filename => 'bogus' )->get, 'foo.txt', 'filename = foo.txt (bare)');
$content_disposition = 'attachment; filename="foo.txt"';
is(Alien::Base::ModuleBuild::File->new( repository => $repo, filename => 'bogus' )->get, 'foo.txt', 'filename = foo.txt (double quotes)');
$content_disposition = 'attachment; filename="foo with space.txt" and some other stuff';
is(Alien::Base::ModuleBuild::File->new( repository => $repo, filename => 'bogus' )->get, 'foo with space.txt', 'filename = foo with space.txt (double quotes with space)');
$content_disposition = 'attachment; filename=foo.txt and some other stuff';
is(Alien::Base::ModuleBuild::File->new( repository => $repo, filename => 'bogus' )->get, 'foo.txt', 'filename = foo.txt (space terminated)');
};
subtest 'check_http_response()' => sub {
subtest '599 no SSL' => sub {
my $res = {
'reason' => 'Internal Exception',
'url' => 'https://mytest.test',
'success' => '',
'status' => 599,
'headers' => {
'content-type' => 'text/plain',
'content-length' => 110,
},
'content' => "IO::Socket::SSL 1.42 must be installed for https support\n" .
"Net::SSLeay 1.49 must be installed for https support\n",
};
is(
[Alien::Base::ModuleBuild::Repository::HTTP->check_http_response($res)],
[1, "IO::Socket::SSL 1.42 must be installed for https support\n" .
"Net::SSLeay 1.49 must be installed for https support\n" .
"See https://github.com/PerlAlien/Alien-Base-ModuleBuild/issues/6#issuecomment-417097485",
{ 'content-type' => 'text/plain', 'content-length' => 110 }, "https://mytest.test" ]
);
};
subtest '599 other' => sub {
my $res = {
'reason' => 'Internal Exception',
'url' => 'https://mytest.test',
'success' => '',
'status' => 599,
'headers' => {
'content-type' => 'text/plain',
'content-length' => 13,
},
'content' => "Some Error!\n",
};
is(
[Alien::Base::ModuleBuild::Repository::HTTP->check_http_response($res)],
[1, "Some Error!\n",
{ 'content-type' => 'text/plain', 'content-length' => 13 }, "https://mytest.test" ]
);
};
subtest '404 bad url' => sub {
my $res = {
'headers' => {
'content-type' => 'text/plain',
'content-length' => length("404 Not Found\n"),
},
'url' => 'https://mytest.test/bogus',
'protocol' => 'HTTP/1.1',
'status' => '404',
'success' => '',
'reason' => 'Not Found',
'content' => "404 Not Found\n",
};
is(
[Alien::Base::ModuleBuild::Repository::HTTP->check_http_response($res)],
[1, "404 Not Found",
{ 'content-type' => 'text/plain', 'content-length' => 14 }, "https://mytest.test/bogus" ],
);
};
};
done_testing;
( run in 0.448 second using v1.01-cache-2.11-cpan-efa8479b9fe )