From 0a0bf29616cae2ce8927f1c63cd327098556cd88 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 25 Dec 2018 10:21:27 +0100 Subject: Add integration test Signed-off-by: Florian Pritz --- lib/App/ArchLinux/PackagerTools/Pacman.pm | 4 + t/PackagerTools.t | 153 ++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 t/PackagerTools.t diff --git a/lib/App/ArchLinux/PackagerTools/Pacman.pm b/lib/App/ArchLinux/PackagerTools/Pacman.pm index e1c6300..287d2a9 100644 --- a/lib/App/ArchLinux/PackagerTools/Pacman.pm +++ b/lib/App/ArchLinux/PackagerTools/Pacman.pm @@ -7,6 +7,10 @@ use Log::Any qw($log); use App::ArchLinux::PackagerTools::CPAN; + +# TODO: Split this class so that the external calls (to expac) are in a +# dedicated class and this class becomes testable. Also update +# t/PackagerTools.t accordingly afterwards. =head1 NAME App::ArchLinux::PackagerTools::Pacman - Methods to interact with pacman diff --git a/t/PackagerTools.t b/t/PackagerTools.t new file mode 100644 index 0000000..68a3459 --- /dev/null +++ b/t/PackagerTools.t @@ -0,0 +1,153 @@ +use strictures 2; + +use Log::Any::Adapter ('TAP'); +use Test::More; +use Test::MockObject; +use Test::Differences; +use Test::Exception; + +use CHI; + +use App::ArchLinux::PackagerTools; +use App::ArchLinux::PackagerTools::Cache; +use App::ArchLinux::PackagerTools::CPAN; +use App::ArchLinux::PackagerTools::Pacman; + +=head1 DESCRIPTION + +Integration test that tests PackagerTools->get_filtered_updateable_packages(). + +It creates an environment that has 4 faked CPAN distributions: + +* Test::FOO which has version 1.2.0 in the repository and 1.2.3 in CPAN + +* Bar which has version 0.5 in both places and thus NO update + +* foobar-blub which has version 0.9 in the repository and 1.0 in CPAN. It is +however not maintained by 'test-maintainer' or 'joe' and thus should NOT be +listed in the output. + +* Diff::Maint which has version 1.1 in the repository and 3.0 in CPAN. It is +maintained by 'joe'. + +This test verifies as much of the available classes as possible. Currently the +Pacman class is mocked and NOT verified due to it calling external programs +(TODO: fix this). + +The 02packages "file" in this test contains some old modules from distributions +that also contain newer modules. These should be ignored by the CPAN class and +not influence the result. + +=cut + +my $details_fetcher = Test::MockObject->new();# +my $pkgdata = 'File: 02packages.details.txt +URL: http://www.perl.com/CPAN/modules/02packages.details.txt +Description: Package names found in directory $CPAN/authors/id/ +Columns: package name, version, path +Intended-For: Automated fetch routines, namespace documentation. +Written-By: PAUSE version 1.005 +Line-Count: 219941 +Last-Updated: Tue, 25 Dec 2018 06:54:25 GMT + +A1z::HTML5::Template 0.20 C/CE/CEEJAY/A1z-HTML5-Template-0.20.tar.gz +a2crd 0.972 J/JV/JV/App-Music-ChordPro-0.972.tar.gz +A_Third_Package undef C/CL/CLEMBURG/Test-Unit-0.13.tar.gz +AAA::Demo undef J/JW/JWACH/Apache-FastForward-1.1.tar.gz +AAA::eBay undef J/JW/JWACH/Apache-FastForward-1.1.tar.gz +AAAA::Crypt::DH 0.06 B/BI/BINGOS/AAAA-Crypt-DH-0.06.tar.gz +AAAA::Mail::SpamAssassin 0.002 S/SC/SCHWIGON/AAAA-Mail-SpamAssassin-0.002.tar.gz +AAAAAAAAA 1.01 M/MS/MSCHWERN/AAAAAAAAA-1.01.tar.gz +AAC::Pvoice 0.91 J/JO/JOUKE/AAC-Pvoice-0.91.tar.gz +AAC::Pvoice::Bitmap 1.12 J/JO/JOUKE/AAC-Pvoice-0.91.tar.gz +AAC::Pvoice::Dialog 1.01 J/JO/JOUKE/AAC-Pvoice-0.91.tar.gz +Test::FOO 1.2.3 T/TE/TEST/Test-FOO-1.2.3.tar.gz +Test::FOO::Mod 1.2.3 T/TE/TEST/Test-FOO-1.2.3.tar.gz +Test::FOO::Old 0.9 T/TE/TEST/Test-FOO-0.9.tar.gz +Bar 0.5 T/TE/TEST/Bar-0.5.tar.gz +Foobar::Blub 1.0 T/TE/TEST/foobar-blub-1.0.tar.gz +Diff::Old 0.5 T/TE/TEST/Diff-Maint-0.5.tar.gz +Diff::Maint 3.0 T/TE/TEST/Diff-Maint-3.0.tar.gz +'; +$details_fetcher->set_always('get_packages_data', $pkgdata); + +my $context = {}; + +my $config = Test::MockObject->new(); +$config->set_always('get_config', { + cpan => {cache_timeout => '1m'}, + allowed_maintainers => ['test-maintainer', 'joe'], +}); + +my $chi = CHI->new( driver => 'Memory', datastore => {}); +my $cache = App::ArchLinux::PackagerTools::Cache->new_no_defaults($context, {CHI => $chi}); +my $cpan = App::ArchLinux::PackagerTools::CPAN->new_no_defaults($context, {packages_details_fetcher => $details_fetcher, cache => $cache, config => $config}); + +# This returns the version in CPAN +my $pacman = Test::MockObject->new(); +$pacman->set_always('get_perl_distributions', [ + {dist_name => 'Test::FOO', version => '1.2.3'}, + {dist_name => 'Bar', version => '0.5'}, + {dist_name => 'foobar-blub', version => '1.0'}, + {dist_name => 'Diff::Maint', version => '3.0'}, + ]); + +# This returns the version in the repository +$pacman->mock('get_perl_distribution_versions', sub { + eq_or_diff($_[1], [qw(Test::FOO Bar foobar-blub Diff::Maint)], 'get_perl_distribution_versions called with expected arguments'); + return { + 'Test::FOO' => '1.2.0', + 'Bar' => '0.5', + 'foobar-blub' => '0.9', + 'Diff::Maint' => '1.0', + }; + }); +$pacman->mock('get_perl_pkgname', sub { + return 'perl-test-foo' if $_[1] eq 'Test::FOO'; + return 'perl-bar' if $_[1] eq 'Bar'; + return 'perl-foobar-blub' if $_[1] eq 'foobar-blub'; + return 'perl-diff-maint' if $_[1] eq 'Diff::Maint'; + fail('Unexpected distribution name'); + }); + +my $archweb = Test::MockObject->new(); +$archweb->mock('get_maintainers', sub { + return [{name => 'test-maintainer'}] if $_[1] eq 'perl-test-foo'; + return [{name => 'test-maintainer'}] if $_[1] eq 'perl-bar-foo'; + return [{name => 'somebody'}] if $_[1] eq 'perl-foobar-blub'; + return [{name => 'somebody'}, {name => 'joe'}] if $_[1] eq 'perl-diff-maint'; + fail('Unexpected distribution name'); + }); + +my $app = App::ArchLinux::PackagerTools->new_no_defaults($context, {cpan => $cpan, pacman => $pacman, archweb => $archweb, config => $config}); + +# Actual testing here +eq_or_diff($app->get_filtered_updateable_packages(), [ + { + cpan_version => '1.2.3', + dist_name => 'Test::FOO', + maintainers => [ + { + name => 'test-maintainer', + }, + ], + pkgname => 'perl-test-foo', + repo_version => '1.2.0' + }, + { + cpan_version => '3.0', + dist_name => 'Diff::Maint', + maintainers => [ + { + name => 'somebody', + }, + { + name => 'joe', + }, + ], + pkgname => 'perl-diff-maint', + repo_version => '1.0' + }, +], 'Filtered list of updateable packages should include Test::FOO, but NOT foobar-blub'); + +done_testing; -- cgit v1.2.3-24-g4f1b