aboutsummaryrefslogtreecommitdiffstats
path: root/t/rpmdb.t
blob: 79f823c7767005dc74199cd4c6f9b8feb56d6bb9 (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
#!/usr/bin/perl

use strict ;
use warnings ;
use Test::More;
use URPM;
if (-e '/etc/debian_version' || `uname -a` =~ /BSD/i) {
    plan skip_all => "*BSD/Debian/Ubuntu do not have a system wide rpmdb";
} else {
    plan tests => 7;
}

my ($count, @all_pkgs_extern, @all_pkgs);
my ($pkg_perl, $count_perl, $pkg_perl_extern);
{
    my $db;
    ok($db = URPM::DB::open, 'DB opened');

    @all_pkgs_extern = sort { $a cmp $b } split /\n/ => qx(rpm -qa --nosignature --qf '%{name}-%{version}-%{release}\n');
    ok(@all_pkgs_extern > 0, 'There are RPMs');

    my $perl = -e '/etc/redhat-release' || -e '/etc/mageia-release' ? qx(rpm -qf /usr/bin/perl --qf '%{name}') : 'perl';
    $count = $db->traverse(sub {
	    my ($pkg) = @_;
	    my ($name, $version, $release, $arch) = $pkg->fullname;
	    #- arch is void for -pubkey- package.
	    my $fullname = "$name-$version-$release";
	    push @all_pkgs, $fullname;
	    $pkg_perl_extern = $fullname if $name eq $perl;
	});

    $count_perl = $db->traverse_tag('name', [$perl], sub {
	    my ($pkg) = @_;
	    my ($name, $version, $release) = $pkg->fullname;
	    $pkg_perl = "$name-$version-$release";
	});
}
is($count, @all_pkgs_extern,
    'traversed same num of packages than given by rpm -qa');
is($count, @all_pkgs,
    'traversed each package once');
is($count_perl, 1, q(there's exactly 1 "perl" package));
is($pkg_perl, $pkg_perl_extern, '... with the correct fullname');

my @all_pkgs_sorted = sort { $a cmp $b } @all_pkgs;
my $bad_pkgs = 0;
foreach (0..$#all_pkgs_sorted) {
    $all_pkgs_sorted[$_] eq $all_pkgs_extern[$_] and next;
    diag($all_pkgs_extern[$_] . " vs " . $all_pkgs_sorted[$_]);
    ++$bad_pkgs;
}
is($bad_pkgs, 0, 'no mismatch between package lists');