File: 06_policy.t

package info (click to toggle)
libapt-pkg-perl 0.1.43
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 316 kB
  • sloc: perl: 1,285; ansic: 201; makefile: 3
file content (81 lines) | stat: -rw-r--r-- 1,489 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl

# AptPkg::Policy tests

BEGIN { print "1..8\n" }

use AptPkg::Config '$_config';
use AptPkg::System '$_system';
use AptPkg::Cache;
use AptPkg::Policy;

$ENV{APT_CONFIG} = 't/cache/etc/apt.conf';

$_config->init;
$_system = $_config->system;

print "ok 1\n";

my $cache = AptPkg::Cache->new;
my $policy = $cache->policy;

# policy created
unless ($policy)
{
    print "not ok 2\n";
    exit;
}

# package "a" exists
if (my $a = $cache->{a})
{
    print "ok 2\n";

    # expect stable candidate
    my $c = $policy->candidate($a);
    print 'not ' unless $c and $c->{VerStr} eq '0.1';
    print "ok 3\n";

    # get archive priorities
    my %prio;
    for my $v (@{$a->{VersionList}})
    {
	for my $f (map $_->{File}, @{$v->{FileList}})
	{
	    $prio{$1} = $policy->priority($f)
		if $f->{FileName} =~ /_dists_([^_]+)_main_/;
	}
    }

    # default prio
    print 'not ' unless $prio{stable} eq '500';
    print "ok 4\n";

    # pinned
    print 'not ' unless $prio{testing} eq '50';
    print "ok 5\n";
}
else
{
    print "not ok 2 # package a missing\n";
    print "ok $_ # skip\n" for 3..5;
}

if (my $b = $cache->{b})
{
    print "ok 6\n";

    # expect pinned candidate
    my $c = $policy->candidate($b);
    print 'not ' unless $c and $c->{VerStr} eq '0.2-1';
    print "ok 7\n";

    my $p = $policy->priority($c);
    print 'not ' unless $p == 1001;
    print "ok 8\n";
}
else
{
    print "not ok 6 # package b missing\n";
    print "ok $_ # skip\n" for 7..8;
}