summaryrefslogtreecommitdiffstats
path: root/t/PackagerTools.t
blob: dace577f8e9ef64e871bc643ec46e5d47b0a42d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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 and Diff::Maint, but NOT foobar-blub');

done_testing;