summaryrefslogtreecommitdiffstats
path: root/t/superuser--rpmnew.t
blob: 18012cd6b18b7e30b4e109e4a07e9cf3b6253695 (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
#!/usr/bin/perl

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

my $medium_name = 'rpmnew';

my @names = ('config-noreplace', 'config', 'normal');

need_root_and_prepare();

my $rpm_cmd = "rpm --root $::pwd/root -U";
my $urpmi_cmd = urpmi_cmd();

test1($rpm_cmd);
test2($rpm_cmd);
test3($rpm_cmd);
test1($urpmi_cmd);
test2($urpmi_cmd);
test3($urpmi_cmd);

sub test1 {
    my ($cmd) = @_;

    test($cmd,
	 ['orig', 'orig', 'orig'],
	 ['orig', 'orig', 'orig'],
	 ['changed', 'changed', 'changed']);

    check_no_etc_files();
}

sub test2 {
    my ($cmd) = @_;

    mkdir "$::pwd/root/etc";
    system("echo orig > $::pwd/root/etc/$_") foreach @names;

    test($cmd,
	 ['orig', 'orig', 'orig'],
	 ['orig', 'orig', 'orig'],
	 ['changed', 'changed', 'changed']);

    check_no_etc_files();
}

sub test3 {
    my ($cmd) = @_;

    mkdir "$::pwd/root/etc";
    system("echo foo > $::pwd/root/etc/$_") foreach @names;

    test($cmd, 
	 ['foo', 'orig', 'orig'],
	 ['foo', 'orig', 'orig'],
	 ['foo', 'changed', 'changed']);

    check_one_content('<removed>', 'config.rpmorig', 'foo');
    check_one_content('<removed>', 'config-noreplace.rpmsave', 'foo');
    check_one_content('<removed>', 'config-noreplace.rpmnew', 'changed');
    ok(unlink("$::pwd/root/etc/config.rpmorig"), 'unlink .rpmorig');
    ok(unlink("$::pwd/root/etc/config-noreplace.rpmsave"), 'unlink .rpmsave');
    ok(unlink("$::pwd/root/etc/config-noreplace.rpmnew"), 'unlink .rpmnew');

    check_no_etc_files();
}

sub check_no_etc_files() {
    if (my @l = grep { !m!/urpmi|rpm$! } glob("$::pwd/root/etc/*")) {
	fail(join(' ', @l) . " files should not be there");
    }
}

sub check_content {
    my ($rpm, $config_noreplace, $config, $normal) = @_;

    check_one_content($rpm, 'config-noreplace', $config_noreplace);
    check_one_content($rpm, 'config', $config);
    check_one_content($rpm, 'normal', $normal);
}

sub check_one_content {
    my ($rpm, $name, $val) = @_;
    my $s = `cat $::pwd/root/etc/$name`;
    chomp $s;
    is($s, $val, "$name for $rpm");
}

sub test {
    my ($cmd, $v1, $v2, $v3) = @_;

    system_("$cmd media/$medium_name/a-1-*.rpm");
    check_installed_fullnames("a-1-1");
    check_content('a-1', @$v1);

    system_("$cmd media/$medium_name/a-2-*.rpm");
    check_installed_fullnames("a-2-1");
    check_content('a-2', @$v2);

    system_("$cmd media/$medium_name/a-3-*.rpm");
    check_installed_fullnames("a-3-1");
    check_content('a-3', @$v3);

    system_("rpm --root $::pwd/root -e a");
}