Peertube-dl/t/downloaders/gocdn.t

63 lines
1.9 KiB
Perl
Raw Normal View History

use strict;
use warnings;
use feature 'say';
use Test::Most tests => 2;
use Test::MockObject;
use Peertube::DL::Downloaders;
use JSON;
{
# GIVEN
my $ua = Test::MockObject->new;
my $base_response = Test::MockObject->new;
my $gocdn_response = Test::MockObject->new;
my $animeflv_response_file = 't/downloaders/animeflv_example_response.html';
my $animeflv_response_decoded;
my $download_data;
my $expected_download_data_url = 'https://example.com/anime_correct_url';
my $expected_download_data = { filename => 'animu-1.mp4', url => $expected_download_data_url };
open my $fh, '<', $animeflv_response_file;
$animeflv_response_decoded = join( '', <$fh> );
close $fh;
my $gocdn_url;
my $expected_gocdn_url =
'https://streamium.xyz/gocdn.php?v=QmoyaEVscFUwbDJkeUtaSVhZVTFOY2g4WkJ5akErWEhnNXJDVmJXVmFVK29MU1NUc1hXSFIxT1lJMzJ6YzdueXgvbzFkeFNJTU1kQWJ6MGkxNlFkeDFpZDZ3R01reDlWYUlqaEVmZldWaVZFVzlOQ2pESlA2RHJ4MFdCNTVnczQ=';
$ua->mock(
get => sub {
my $self = shift;
my $url = shift;
say STDERR $url;
$gocdn_url = $url;
return $gocdn_response;
}
);
$base_response->mock(
decoded_content => sub {
return $animeflv_response_decoded;
},
base => sub {
return 'https://animeflv.net/ver/animu-1';
}
);
$gocdn_response->mock(
is_success => sub {
1;
},
decoded_content => sub {
JSON::encode_json( { file => $expected_download_data_url } );
}
);
$download_data = Peertube::DL::Downloaders::gocdn( $ua, $base_response );
is $gocdn_url, $expected_gocdn_url, 'The url got from gocdn is correct.';
is_deeply $download_data, $expected_download_data, 'The download data got is the expected one.';
}