Github-ReleaseFetcher
view release on metacpan or search on metacpan
t/Github-ReleaseFetcher.t view on Meta::CPAN
use strict;
use warnings;
use Test2::V0;
use Test::Mock::HTTP::Tiny;
use Github::ReleaseFetcher;
# I'll give you one guess why I wrote this module
my ( $user, $project ) = qw{SeleniumHQ selenium};
my $bad_version_request = {
url => "$Github::ReleaseFetcher::BASE_URI/$user/$project/releases/latest",
method => 'GET',
args => {},
response => {
success => 0,
content => 'I already have a wristwatch',
reason => 'u dumb',
}
};
my $good_version_request = {
url => "$Github::ReleaseFetcher::BASE_URI/$user/$project/releases/latest",
method => 'GET',
args => {},
response => {
success => 1,
url => "$Github::ReleaseFetcher::BASE_URI/$user/$project/releases/666",
}
};
my $bad_listing_request = {
url => "$Github::ReleaseFetcher::BASE_URI/$user/$project/releases/expanded_assets/666",
method => 'GET',
args => {},
response => {
success => 0,
content => 'I already have a wristwatch',
reason => 'u dumb',
}
};
local $/ = "";
my $content = <DATA>;
my $good_listing_request = {
url => "$Github::ReleaseFetcher::BASE_URI/$user/$project/releases/expanded_assets/666",
method => 'GET',
args => {},
response => {
success => 1,
content => $content,
}
};
Test::Mock::HTTP::Tiny->set_mocked_data( [$bad_version_request] );
like( dies { Github::ReleaseFetcher::fetch( undef, $user, $project ) }, qr/u dumb/, "Failing to redirect to the release version explodes" );
Test::Mock::HTTP::Tiny->set_mocked_data( [ $good_version_request, $bad_listing_request ] );
like( dies { Github::ReleaseFetcher::fetch( undef, $user, $project ) }, qr/u dumb/, "expanded assets page failing explodes" );
my @gut = (
'http://github.com//SeleniumHQ/selenium/releases/download/selenium-4.23.0/selenium-dotnet-strongnamed-4.23.0.zip',
'http://github.com//SeleniumHQ/selenium/releases/download/selenium-4.23.0/selenium-java-4.23.0.zip',
'http://github.com//SeleniumHQ/selenium/releases/download/selenium-4.23.0/selenium-server-4.23.1.jar',
'http://github.com//SeleniumHQ/selenium/releases/download/selenium-4.23.0/selenium-server-4.23.0.zip',
'http://github.com//SeleniumHQ/selenium/releases/download/selenium-4.23.0/selenium-dotnet-4.23.0.zip',
'http://github.com//SeleniumHQ/selenium/archive/refs/tags/selenium-4.23.0.tar.gz',
'http://github.com//SeleniumHQ/selenium/archive/refs/tags/selenium-4.23.0.zip',
'http://github.com//SeleniumHQ/selenium/releases/download/selenium-4.23.0/selenium-java-4.23.1.zip',
'http://github.com//SeleniumHQ/selenium/releases/download/selenium-4.23.0/selenium-server-4.23.0.jar',
'http://github.com//SeleniumHQ/selenium/releases/download/selenium-4.23.0/selenium-server-4.23.1.zip'
);
Test::Mock::HTTP::Tiny->set_mocked_data( [ $good_version_request, $good_listing_request ] );
my @out = Github::ReleaseFetcher::fetch( undef, $user, $project );
# Test2's bag builder is BAD DO NOT USE!!!!!!!!!!!!
@out = sort @out;
@gut = sort @gut;
is( \@out, \@gut, "Got expected output when process succeeds" );
done_testing();
__DATA__
<div data-view-component="true" class="Box Box--condensed mt-3">
<ul data-view-component="true">
<li data-view-component="true" class="Box-row d-flex flex-column flex-md-row"> <div data-view-component="true" class="d-flex flex-justify-start col-12 col-lg-9">
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-package color-fg-muted">
<path d="m8.878.392 5.25 3.045c.54.314.872.89.872 1.514v6.098a1.75 1.75 0 0 1-.872 1.514l-5.25 3.045a1.75 1.75 0 0 1-1.756 0l-5.25-3.045A1.75 1.75 0 0 1 1 11.049V4.951c0-.624.332-1.201.872-1.514L7.122.392a1.75 1.75 0 0 1 1.756 0ZM7.875 1.69l-4.63...
</svg>
<a href="/SeleniumHQ/selenium/releases/download/selenium-4.23.0/selenium-dotnet-4.23.0.zip" rel="nofollow" data-turbo="false" data-view-component="true" class="Truncate">
<span data-view-component="true" class="Truncate-text text-bold">selenium-dotnet-4.23.0.zip</span>
<span data-view-component="true" class="Truncate-text"></span>
</a></div> <div data-view-component="true" class="d-flex flex-auto flex-justify-end col-md-4 ml-3 ml-md-0 mt-1 mt-md-0 pl-1 pl-md-0">
<span style="white-space: nowrap;" data-view-component="true" class="color-fg-muted text-sm-left flex-auto ml-md-3">10.4 MB</span>
<span style="white-space: nowrap;" data-view-component="true" class="color-fg-muted text-right flex-shrink-0 flex-grow-0 ml-3"><relative-time datetime="2024-07-19T10:27:29Z" class="no-wrap" prefix="">2024-07-19T10:27:29Z</relative-time></sp...
</div></li>
<li data-view-component="true" class="Box-row d-flex flex-column flex-md-row"> <div data-view-component="true" class="d-flex flex-justify-start col-12 col-lg-9">
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-package color-fg-muted">
<path d="m8.878.392 5.25 3.045c.54.314.872.89.872 1.514v6.098a1.75 1.75 0 0 1-.872 1.514l-5.25 3.045a1.75 1.75 0 0 1-1.756 0l-5.25-3.045A1.75 1.75 0 0 1 1 11.049V4.951c0-.624.332-1.201.872-1.514L7.122.392a1.75 1.75 0 0 1 1.756 0ZM7.875 1.69l-4.63...
</svg>
<a href="/SeleniumHQ/selenium/releases/download/selenium-4.23.0/selenium-dotnet-strongnamed-4.23.0.zip" rel="nofollow" data-turbo="false" data-view-component="true" class="Truncate">
( run in 0.965 second using v1.01-cache-2.11-cpan-364913b4093 )