Youri-Package
view release on metacpan or search on metacpan
my $last_change_author =
'Guillaume Rousse <guillomovitch@mandriva.org> 3.03-11mdv2007.0';
my $last_change_time = 1149847200;
my $last_change_raw_text = "- %mkrel\n- rpmbuildupdate aware",
my $last_change_text_items = [
'%mkrel',
'rpmbuildupdate aware'
];
my @classes = qw/
Youri::Package::RPM::URPM
Youri::Package::RPM::Test
/;
push @classes, 'Youri::Package::RPM::RPM4' if RPM4->require();
push @classes, 'Youri::Package::RPM::RPM' if RPM->require();
my $dir = dirname($0);
my $rpm = 'cowsay-3.03-11mdv2007.0.noarch.rpm';
my ($old_rpm) = Youri::Package::RPM::Generator->new(tags => {
name => 'cowsay',
version => '3.03',
release => '10mdv2007.0',
buildarch => 'noarch'
})->get_binaries();
my ($new_rpm) = Youri::Package::RPM::Generator->new(tags => {
name => 'cowsay',
version => '3.03',
release => '12mdv2007.0',
buildarch => 'noarch'
})->get_binaries();
my $fake_rpm = 'foobar.rpm';
plan(tests => 49 * scalar @classes);
foreach my $class (@classes) {
$class->require();
my $temp_dir = tempdir(CLEANUP => $ENV{TEST_DEBUG} ? 0 : 1);
my $file = "$dir/$rpm";
my $old_file = "$old_rpm";
my $new_file = "$new_rpm";
my $fake_file = "$temp_dir/$fake_rpm";
# instanciation errors
dies_ok { $class->new(file => undef) } 'undefined file';
dies_ok { $class->new(file => $fake_file) } 'non-existant file';
system('touch', $fake_file);
chmod 0000, $fake_file;
dies_ok { $class->new(file => $fake_file) } 'non-readable file';
chmod 0644, $fake_file;
dies_ok { $class->new(file => $fake_file) } 'non-rpm file';
my $package;
if ($class eq 'Youri::Package::RPM::Test') {
# this one need a little help
$package = $class->new(
file => $file,
tags => {
summary => 'Configurable talking cow',
url => 'http://www.nog.net/~tony/warez/cowsay.shtml',
packager => 'Guillaume Rousse <guillomovitch@mandriva.org>',
gpg_key => '26752624',
},
requires => $requires,
provides => $provides,
obsoletes => $obsoletes,
conflicts => $conflicts,
files => $files,
changes => [[
'Guillaume Rousse <guillomovitch@mandriva.org> 3.03-11mdv2007.0',
1149847200,
"- %mkrel\n- rpmbuildupdate aware"
]]
);
} else {
$package = $class->new(file => $file);
}
isa_ok($package, $class);
# tag value access
is($package->get_name(), 'cowsay', 'get name directly');
is($package->get_tag('name'), 'cowsay', 'get name indirectly');
is($package->get_version(), '3.03', 'get version directly');
is($package->get_tag('version'), '3.03', 'get version indirectly');
is($package->get_release(), '11mdv2007.0', 'get release directly');
is($package->get_tag('release'), '11mdv2007.0', 'get release indirectly');
is($package->get_arch(), 'noarch', 'get arch directly');
is($package->get_tag('arch'), 'noarch', 'get arch indirectly');
is($package->get_summary(), 'Configurable talking cow', 'get summary directly');
is($package->get_tag('summary'), 'Configurable talking cow', 'get summary indirectly');
is($package->get_url(), 'http://www.nog.net/~tony/warez/cowsay.shtml', 'get url directly');
is($package->get_tag('url'), 'http://www.nog.net/~tony/warez/cowsay.shtml', 'get url indirectly');
is($package->get_packager(), 'Guillaume Rousse <guillomovitch@mandriva.org>', 'get packager directly');
is($package->get_tag('packager'), 'Guillaume Rousse <guillomovitch@mandriva.org>', 'get packager indirectly');
is($package->get_file_name(), 'cowsay-3.03-11mdv2007.0.noarch.rpm', 'file name');
is($package->get_revision(), '3.03-11mdv2007.0', 'revision');
# name formating
is($package->as_formated_string('%{name}-%{version}-%{release}'), 'cowsay-3.03-11mdv2007.0', 'formated string name');
is($package->as_string(), 'cowsay-3.03-11mdv2007.0.noarch', 'default string');
is($package, 'cowsay-3.03-11mdv2007.0.noarch', 'stringification');
# type
ok(!$package->is_source(), 'not a source package');
ok($package->is_binary(), 'a binary package');
is($package->get_type(), 'binary', 'a binary package');
# gpg key
is($package->get_gpg_key(), '26752624', 'get gpg key');
# dependencies
is_deeply(
[ $package->get_requires() ],
$requires,
'requires'
);
is_deeply(
[ $package->get_provides() ],
$provides,
'provides'
);
is_deeply(
[ $package->get_obsoletes() ],
$obsoletes,
'obsoletes'
);
is_deeply(
[ $package->get_conflicts() ],
$conflicts,
'conflicts'
);
# files
is_deeply(
[ $package->get_files() ],
$files,
'files'
);
# changelog
is(
$package->get_last_change()->get_author(),
$last_change_author,
'last change has expected author'
);
is(
$package->get_last_change()->get_time(),
$last_change_time,
'last change has expected date'
);
is(
$package->get_last_change()->get_raw_text(),
$last_change_raw_text,
'last change has expected raw text'
);
is_deeply(
[ $package->get_last_change()->get_text_items() ],
$last_change_text_items,
'last change has expected text items'
);
# comparison tests
my $old_package = $class->new(file => $old_file);
my $new_package = $class->new(file => $new_file);
is($package->compare($package), 0, 'comparison with self');
is($package->compare($old_package), 1, 'comparison with older');
is($package->compare($new_package), -1, 'comparison with newer');
dies_ok {
$package->compare('foobar');
} 'comparison with something else as a package';
ok($package->satisfy_range('>= 3.03-11mdv2007.0'), 'range test');
ok($package->satisfy_range('<= 3.03-11mdv2007.0'), 'range test');
ok($package->satisfy_range('== 3.03-11mdv2007.0'), 'range test');
ok($package->satisfy_range('> 3.03-10mdv2007.0'), 'range test');
ok($package->satisfy_range('< 3.03-12mdv2007.0'), 'range test');
SKIP: {
skip "not implemented yet", 3
if $class eq 'Youri::Package::RPM::Test';
skip "rpm4 has no error control for signature", 3
if $class eq 'Youri::Package::RPM::RPM4';
skip "rpm has no error control for signature", 3
if $class eq 'Youri::Package::RPM::RPM';
skip "rpmsign not available", 3
if ! which("rpmsign");
# signature test
copy($file, $temp_dir);
$package = $class->new(file => "$temp_dir/$rpm");
throws_ok {
$package->sign('Youri', "$dir/gpghome", 'Youri sux')
} qr/^Signature error:/, 'signing with wrong key';
lives_ok {
$package->sign('Youri', "$dir/gpghome", 'Youri rulez')
} 'signing with correct key';
$package = $class->new(file => "$temp_dir/$rpm");
is($package->get_gpg_key(), '2333e817', 'get gpg key');
}
}
( run in 0.510 second using v1.01-cache-2.11-cpan-df04353d9ac )