summaryrefslogtreecommitdiffstats
path: root/t/superuser--priority-upgrade.t
blob: 26252f00da62996f8d8382fe524d6f6d33af55bc (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
#!/usr/bin/perl

use strict;
use lib '.', 't';
use helper;
use Expect;
use urpm::util;
use Test::More 'no_plan';

need_root_and_prepare();

$ENV{TESTING_priority_upgrade} = 1;
$ENV{PERL5LIB} = ".."; #- for restart with local urpmi
my $name = 'priority-upgrade';

test('a b', 'a', 'a', 'b');

test('a-strict b', 'a-strict', 'a-strict b bb1', 'b',
     [ 'What is your choice', "\n" ],
     [ 'Proceed with the installation of the 2 packages?', "\n" ],
     [ 'restarting urpmi', '' ],
 );

test_ab_auto_select('', 
     [ 'What is your choice', "\n" ],
     [ 'Proceed with the installation of the 3 packages?', "\n" ],
 );
test_ab_auto_select('a',
     [ 'Proceed with the installation of one package?', "\n" ],
     [ 'restarting urpmi', '' ],
     [ 'What is your choice', "\n" ],
     [ 'Proceed with the installation of the 2 packages?', "\n" ],
 );	
test_ab_auto_select('b',
     [ 'What is your choice', "\n" ],
     [ 'Proceed with the installation of the 2 packages?', "\n" ],
     [ 'restarting urpmi', '' ],
     [ 'Proceed with the installation of one package?', "\n" ],
 );	
test_ab_auto_select('a,b',
     [ 'What is your choice', "\n" ],
     [ 'Proceed with the installation of the 3 packages?', "\n" ],
 );


sub test_ab_auto_select {
    my ($priority_upgrade, @expected) = @_;
    test('a b', undef, 'a b bb1', $priority_upgrade, @expected);
}

sub test {
    my ($pkgs_v1, $wanted_v2, $pkgs_v2, $priority_upgrade, @expected) = @_;

    unlink "$::pwd/media/$name";
    symlink "$name-1", "$::pwd/media/$name";

    urpmi_addmedia("$name $::pwd/media/$name");    

    if ($priority_upgrade) {
	set_urpmi_cfg_global_options({ 'priority-upgrade' => $priority_upgrade });
    }

    urpmi($pkgs_v1);
    my @pkgs_v1 = split(' ', $pkgs_v1);   
    check_installed_fullnames(map { "$_-1-1" } @pkgs_v1);

    unlink "$::pwd/media/$name";
    symlink "$name-2", "$::pwd/media/$name";

    if ($wanted_v2) {
	urpmi_update('-a');
	urpmi_expected($wanted_v2, \@expected);
    } else {
	urpmi_expected('--auto-update', \@expected);
    }


    my @pkgs_v2 = split(' ', $pkgs_v2);
    my @l = (
	(map { "$_-2-1" } @pkgs_v2),
	(map { "$_-1-1" } difference2(\@pkgs_v1, \@pkgs_v2)),
    );
    check_installed_fullnames(sort @l);

    system_('rm -rf root');
}

sub urpmi_expected {
    my ($options, $expected) = @_;

    if (0) {
	#- try it interactively for debugging
	system_(urpm_cmd('urpmi', '-d') . " $options");
	return;
    }

    my $cmd = urpmi_cmd() . " $options";
    print "# $cmd\n";
    my $expect = Expect->spawn($cmd);

    foreach (@$expected) {
	my ($msg, $to_send) = @$_;

	my $ok = $expect->expect(2, # timeout in seconds 
				 [ $msg => sub { $expect->send($to_send); } ]);
	print "$to_send\n";
	ok($ok, qq(expecting "$msg"));
	$ok or return;
    }

    $expect->expect(2, 
		    [ qr/restarting urpmi/ => sub { fail('not restarting urpmi') } ], 
		    [ 'eof' => sub {} ]);

    $expect->soft_close;
    is($expect->exitstatus, 0, $cmd);
}