summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2006-11-30 13:28:03 +0000
committerPascal Rigaux <pixel@mandriva.com>2006-11-30 13:28:03 +0000
commit37b66b6b34d29c9e628c4a0bbf5babdb5e1340fe (patch)
tree9847ca49d51ce41e951fcabcd0ed6344a3e5009a /t
parente15d45cca3d34d223927cf37f497de3a9703fb78 (diff)
downloadurpmi-37b66b6b34d29c9e628c4a0bbf5babdb5e1340fe.tar
urpmi-37b66b6b34d29c9e628c4a0bbf5babdb5e1340fe.tar.gz
urpmi-37b66b6b34d29c9e628c4a0bbf5babdb5e1340fe.tar.bz2
urpmi-37b66b6b34d29c9e628c4a0bbf5babdb5e1340fe.tar.xz
urpmi-37b66b6b34d29c9e628c4a0bbf5babdb5e1340fe.zip
using --urpmi-root, create some tests using urpmi.addmedia, urpmi, urpme
one drawback of the superuser--*.t is the need to be root (the rpmlib needs it to install in a root partition), so for now "make test" tests *.t but superuser--*.t are skipped. Then as root, run "sudo make test TEST_FILES='t/superuser--*.t'"
Diffstat (limited to 't')
-rw-r--r--t/02create_pkgs.t24
-rw-r--r--t/README6
-rw-r--r--t/SPECS/arch_to_noarch_1.spec28
-rw-r--r--t/SPECS/arch_to_noarch_2.spec28
-rw-r--r--t/SPECS/arch_to_noarch_3.spec29
-rw-r--r--t/SPECS/arch_to_noarch_4.spec28
-rw-r--r--t/SPECS/various.spec38
-rw-r--r--t/helper.pm40
-rw-r--r--t/superuser--arch_to_noarch.t18
-rw-r--r--t/superuser--exclude.t95
10 files changed, 334 insertions, 0 deletions
diff --git a/t/02create_pkgs.t b/t/02create_pkgs.t
new file mode 100644
index 00000000..8a716226
--- /dev/null
+++ b/t/02create_pkgs.t
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More 'no_plan';
+
+chdir 't' if -d 't';
+system('rm -rf BUILD RPMS media');
+for (qw(media BUILD RPMS RPMS/noarch)) {
+ mkdir $_;
+}
+# locally build a test rpms
+foreach my $spec (glob("SPECS/*.spec")) {
+ system_("rpmbuild --quiet --define '_topdir .' -bb --clean $spec");
+ my ($name) = $spec =~ m!([^/]*)\.spec$!;
+ mkdir "media/$name";
+ system_("mv RPMS/*/*.rpm media/$name");
+}
+
+sub system_ {
+ my ($cmd) = @_;
+ system($cmd);
+ ok($? == 0, $cmd);
+}
diff --git a/t/README b/t/README
new file mode 100644
index 00000000..2784568d
--- /dev/null
+++ b/t/README
@@ -0,0 +1,6 @@
+you need to be root to run superuser--*.t,
+with a normal user those tests are simply skipped.
+
+so do:
+- make test
+- sudo make test TEST_FILES='t/superuser--*.t'
diff --git a/t/SPECS/arch_to_noarch_1.spec b/t/SPECS/arch_to_noarch_1.spec
new file mode 100644
index 00000000..05cff446
--- /dev/null
+++ b/t/SPECS/arch_to_noarch_1.spec
@@ -0,0 +1,28 @@
+Summary: arch_to_noarch
+Name: arch_to_noarch
+Version: 1
+Release: 1
+License: x
+Group: x
+Url: x
+BuildRoot: %{_tmppath}/%{name}
+
+%prep
+
+%build
+
+%install
+rm -rf $RPM_BUILD_ROOT
+install -d $RPM_BUILD_ROOT/usr/lib/test-%{name}
+cp /sbin/ldconfig $RPM_BUILD_ROOT/usr/lib/test-%{name}
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%description
+this pkg own a binary file
+
+%files
+%defattr(-,root,root)
+%config(noreplace) /usr/lib/test-%{name}
+
diff --git a/t/SPECS/arch_to_noarch_2.spec b/t/SPECS/arch_to_noarch_2.spec
new file mode 100644
index 00000000..7be6925b
--- /dev/null
+++ b/t/SPECS/arch_to_noarch_2.spec
@@ -0,0 +1,28 @@
+Summary: arch_to_noarch
+Name: arch_to_noarch
+Version: 2
+Release: 1
+License: x
+Group: x
+Url: x
+BuildRoot: %{_tmppath}/%{name}
+
+%prep
+
+%build
+
+%install
+rm -rf $RPM_BUILD_ROOT
+install -d $RPM_BUILD_ROOT/usr/lib/test-%{name}
+cp /sbin/ldconfig $RPM_BUILD_ROOT/usr/lib/test-%{name}
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%description
+this pkg still owns a binary file
+
+%files
+%defattr(-,root,root)
+%config(noreplace) /usr/lib/test-%{name}
+
diff --git a/t/SPECS/arch_to_noarch_3.spec b/t/SPECS/arch_to_noarch_3.spec
new file mode 100644
index 00000000..be9cdb4d
--- /dev/null
+++ b/t/SPECS/arch_to_noarch_3.spec
@@ -0,0 +1,29 @@
+Summary: arch_to_noarch
+Name: arch_to_noarch
+Version: 3
+Release: 1
+License: x
+Group: x
+Url: x
+BuildRoot: %{_tmppath}/%{name}
+BuildArch: noarch
+
+%prep
+
+%build
+
+%install
+rm -rf $RPM_BUILD_ROOT
+install -d $RPM_BUILD_ROOT/usr/lib/test-%{name}
+echo foo > $RPM_BUILD_ROOT/usr/lib/test-%{name}/foo
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%description
+this pkg is now a noarch
+
+%files
+%defattr(-,root,root)
+%config(noreplace) /usr/lib/test-%{name}
+
diff --git a/t/SPECS/arch_to_noarch_4.spec b/t/SPECS/arch_to_noarch_4.spec
new file mode 100644
index 00000000..7eb32705
--- /dev/null
+++ b/t/SPECS/arch_to_noarch_4.spec
@@ -0,0 +1,28 @@
+Summary: arch_to_noarch
+Name: arch_to_noarch
+Version: 4
+Release: 1
+License: x
+Group: x
+Url: x
+BuildRoot: %{_tmppath}/%{name}
+
+%prep
+
+%build
+
+%install
+rm -rf $RPM_BUILD_ROOT
+install -d $RPM_BUILD_ROOT/usr/lib/test-%{name}
+cp /sbin/ldconfig $RPM_BUILD_ROOT/usr/lib/test-%{name}
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%description
+this pkg is now a binary again
+
+%files
+%defattr(-,root,root)
+%config(noreplace) /usr/lib/test-%{name}
+
diff --git a/t/SPECS/various.spec b/t/SPECS/various.spec
new file mode 100644
index 00000000..b7d62e8f
--- /dev/null
+++ b/t/SPECS/various.spec
@@ -0,0 +1,38 @@
+Summary: various
+Name: various
+Version: 1
+Release: 1
+License: x
+Group: x
+Url: x
+BuildRoot: %{_tmppath}/%{name}
+
+%prep
+echo foo > foo
+
+%build
+
+%install
+rm -rf $RPM_BUILD_ROOT
+for i in /etc/test-%{name} \
+ /var/lib/test-%{name}/foo1 /var/lib/test-%{name}/foo2 /var/lib/test-%{name}/foo3 \
+ /usr/share/locale/fr/LC_MESSAGES/test-%{name}.mo \
+ /usr/test-%{name}/foo; do
+ install -d `dirname $RPM_BUILD_ROOT$i`
+ echo foo > $RPM_BUILD_ROOT$i
+done
+
+%find_lang test-%{name}
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%description
+x
+
+%files -f test-%{name}.lang
+%defattr(-,root,root)
+%doc foo
+%config(noreplace) /etc/*
+/var/lib/*
+/usr/test-%{name}
diff --git a/t/helper.pm b/t/helper.pm
new file mode 100644
index 00000000..334700e8
--- /dev/null
+++ b/t/helper.pm
@@ -0,0 +1,40 @@
+package helper;
+
+use Test::More;
+
+my $using_root;
+sub need_root_and_prepare() {
+ if ($< != 0) {
+ #- can't test
+ pass();
+ exit(0);
+ }
+ -d 'media' or die "02create_pkgs.t not done\n";
+
+ system('rm -rf root');
+ isnt(-d 'root', "test root dir can not be removed $!");
+ mkdir 'root';
+ $using_root = 1;
+}
+
+chomp($::pwd = `pwd`);
+my $urpmi_debug_opt = '-q';#'-v --debug';
+
+sub urpmi_addmedia {
+ my ($para) = @_;
+ system_("perl -I.. ../urpmi.addmedia $urpmi_debug_opt --urpmi-root $::pwd/root $para");
+}
+sub urpmi {
+ my ($para) = @_;
+ system_("perl -I.. ../urpmi $urpmi_debug_opt --urpmi-root $::pwd/root --ignoresize $para");
+}
+
+sub system_ {
+ my ($cmd) = @_;
+ system($cmd);
+ ok($? == 0, $cmd);
+}
+
+END { $using_root and system('rm -rf root') }
+
+1;
diff --git a/t/superuser--arch_to_noarch.t b/t/superuser--arch_to_noarch.t
new file mode 100644
index 00000000..3224ea87
--- /dev/null
+++ b/t/superuser--arch_to_noarch.t
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+use strict;
+use Test::More 'no_plan';
+
+chdir 't' if -d 't';
+require './helper.pm';
+
+helper::need_root_and_prepare();
+
+my $name = 'arch_to_noarch';
+
+foreach my $nb (1 .. 4) {
+ my $medium_name = "${name}_$nb";
+ helper::urpmi_addmedia("$medium_name $::pwd/media/$medium_name");
+ helper::urpmi("$name");
+ is(`rpm -qa --root $::pwd/root`, "$name-$nb-1\n");
+}
diff --git a/t/superuser--exclude.t b/t/superuser--exclude.t
new file mode 100644
index 00000000..44a2a1a3
--- /dev/null
+++ b/t/superuser--exclude.t
@@ -0,0 +1,95 @@
+#!/usr/bin/perl
+
+use strict;
+use Test::More 'no_plan';
+
+BEGIN { use_ok 'urpm::cfg' }
+BEGIN { use_ok 'urpm::download' }
+
+chdir 't' if -d 't';
+require './helper.pm';
+
+helper::need_root_and_prepare();
+
+my $name = 'various';
+
+my $urpmi_debug_opt = '-q';#'-v --debug';
+my $urpmi_addmedia = "perl -I.. ../urpmi.addmedia $urpmi_debug_opt --urpmi-root $::pwd/root";
+my $urpmi = "perl -I.. ../urpmi $urpmi_debug_opt --urpmi-root $::pwd/root --ignoresize";
+my $urpme = "perl -I.. ../urpme --urpmi-root $::pwd/root";
+
+my @want = `rpm -qpl media/$name/$name-1-1.*.rpm`;
+
+system_("$urpmi_addmedia $name $::pwd/media/$name");
+
+foreach ([ '', \@want ],
+ [ '--excludedocs', [ grep { !m!^/usr/share/doc! } @want ] ],
+ [ '--excludepath /usr', [ grep { !m!^/usr! } @want ] ],
+ ) {
+ my ($option, $want) = @$_;
+
+ test_rpm_cmdline($option, $want);
+ test_urpmi_cmdline($option, $want);
+ test_urpmi_through_urpmi_cfg($option, $want);
+}
+
+sub test_rpm_cmdline {
+ my ($option, $want) = @_;
+
+ system_("rpm --root $::pwd/root -i $option media/$name/$name-1-1.*.rpm");
+ check("rpm -i $option", $want);
+ system_("rpm --root $::pwd/root -e $name");
+ check('rpm -e', []);
+}
+sub test_urpmi_cmdline {
+ my ($option, $want) = @_;
+
+ system_("$urpmi $option $name");
+ check("urpmi $option", $want);
+ system_("$urpme $name");
+ check('rpm -e', []);
+}
+sub test_urpmi_through_urpmi_cfg {
+ my ($option, $want) = @_;
+
+ set_urpmi_cfg_global_options(cmdline2hash($option));
+ system_("$urpmi $name");
+ check("urpmi ($option in urpmi.cfg)", $want);
+ system_("$urpme $name");
+ check('rpm -e', []);
+ set_urpmi_cfg_global_options({});
+}
+
+sub check {
+ my ($kind, $want) = @_;
+ my @got_all = filter_urpmi_rpm_files(`find root | sed 's/^root//'`);
+ my @got_no_dirs = filter_urpmi_rpm_files(`find root ! -type d | sed 's/^root//'`);
+ is(join('', difference2(\@got_no_dirs, $want)), '', "too many files ($kind)");
+ is(join('', difference2($want, \@got_all)), '', "missing files ($kind)");
+}
+
+sub cmdline2hash {
+ my ($option) = @_;
+ $option =~ /--(\S+)\s*(\S*)/ ? { $1 => $2 } : {};
+}
+
+sub set_urpmi_cfg_global_options {
+ my ($options) = @_;
+ my $f = "root/etc/urpmi/urpmi.cfg";
+ my $config = urpm::cfg::load_config($f);
+ $config->{global} = $options;
+ ok(urpm::cfg::dump_config($f, $config), 'config written');
+}
+
+sub filter_urpmi_rpm_files {
+ grep { !m!^(/dev/null|/etc/urpmi|/etc/rpm/macros|/var/(cache|lib)/(urpmi|rpm))! } @_;
+}
+
+sub system_ {
+ my ($cmd) = @_;
+ system($cmd);
+ ok($? == 0, $cmd);
+}
+sub difference2 { my %l; @l{@{$_[1]}} = (); grep { !exists $l{$_} } @{$_[0]} }
+
+END { system('rm -rf root') }