From 3036fe3904d6e8e7bcfe384457bbb7399f57bf7f Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Mon, 13 Aug 2007 11:26:05 +0000 Subject: new test for file conflicts --- t/data/SPECS/file-conflicts/a.spec | 23 ++++++++++++ t/data/SPECS/file-conflicts/b.spec | 22 +++++++++++ t/data/SPECS/file-conflicts/c.spec | 22 +++++++++++ t/helper.pm | 7 +++- t/superuser--file-conflicts.t | 75 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 t/data/SPECS/file-conflicts/a.spec create mode 100644 t/data/SPECS/file-conflicts/b.spec create mode 100644 t/data/SPECS/file-conflicts/c.spec create mode 100644 t/superuser--file-conflicts.t diff --git a/t/data/SPECS/file-conflicts/a.spec b/t/data/SPECS/file-conflicts/a.spec new file mode 100644 index 00000000..abd35421 --- /dev/null +++ b/t/data/SPECS/file-conflicts/a.spec @@ -0,0 +1,23 @@ +Summary: x +Name: a +Version: 1 +Release: 1 +License: x +Group: x +Url: x +BuildArch: noarch + +%description +x + +%install +rm -rf $RPM_BUILD_ROOT +install -d $RPM_BUILD_ROOT/etc +echo a > $RPM_BUILD_ROOT/etc/foo +echo bar > $RPM_BUILD_ROOT/etc/bar + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +/etc/* diff --git a/t/data/SPECS/file-conflicts/b.spec b/t/data/SPECS/file-conflicts/b.spec new file mode 100644 index 00000000..14e3ad5f --- /dev/null +++ b/t/data/SPECS/file-conflicts/b.spec @@ -0,0 +1,22 @@ +Summary: x +Name: b +Version: 1 +Release: 1 +License: x +Group: x +Url: x +BuildArch: noarch + +%description +x + +%install +rm -rf $RPM_BUILD_ROOT +install -d $RPM_BUILD_ROOT/etc +echo b > $RPM_BUILD_ROOT/etc/foo + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +/etc/* diff --git a/t/data/SPECS/file-conflicts/c.spec b/t/data/SPECS/file-conflicts/c.spec new file mode 100644 index 00000000..17289949 --- /dev/null +++ b/t/data/SPECS/file-conflicts/c.spec @@ -0,0 +1,22 @@ +Summary: x +Name: c +Version: 1 +Release: 1 +License: x +Group: x +Url: x +BuildArch: noarch + +%description +x + +%install +rm -rf $RPM_BUILD_ROOT +install -d $RPM_BUILD_ROOT/etc +echo bar > $RPM_BUILD_ROOT/etc/bar + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +/etc/* diff --git a/t/helper.pm b/t/helper.pm index d7e6d802..eecf5e20 100644 --- a/t/helper.pm +++ b/t/helper.pm @@ -7,7 +7,7 @@ our @EXPORT = qw(need_root_and_prepare urpmi_addmedia urpmi_removemedia urpmi_update urpm_cmd urpmi_cmd urpmi urpme urpmi_cfg set_urpmi_cfg_global_options - system_ + system_ system_should_fail check_installed_fullnames check_installed_names check_nothing_installed check_installed_and_remove check_installed_and_urpme ); @@ -90,6 +90,11 @@ sub system_ { system($cmd); ok($? == 0, $cmd); } +sub system_should_fail { + my ($cmd) = @_; + system($cmd); + ok($? != 0, "should fail: $cmd"); +} sub check_installed_fullnames { diff --git a/t/superuser--file-conflicts.t b/t/superuser--file-conflicts.t new file mode 100644 index 00000000..8580b6f5 --- /dev/null +++ b/t/superuser--file-conflicts.t @@ -0,0 +1,75 @@ +#!/usr/bin/perl + +use strict; +use lib '.', 't'; +use helper; +use Expect; +use urpm::util; +use Test::More 'no_plan'; + +need_root_and_prepare(); + +my $medium_name = 'file-conflicts'; + +urpmi_addmedia("$medium_name $::pwd/media/$medium_name"); + + +test_rpm_same_transaction(); +test_rpm_different_transactions(); + +test_urpmi_same_transaction(); +test_urpmi_different_transactions(); + +sub test_rpm_same_transaction { + # disabled, fail + #test_rpm_i_fail('a', 'b'); + #check_nothing_installed(); + + test_rpm_i_succeeds('a', 'c'); + check_installed_and_remove('a', 'c'); +} + +sub test_rpm_different_transactions { + test_rpm_i_succeeds('a'); + + test_rpm_i_fail('b'); + check_installed_names('a'); + + test_rpm_i_succeeds('c'); + check_installed_and_remove('a', 'c'); +} + +sub test_urpmi_same_transaction { + # disabled, fail + #test_urpmi_fail('a', 'b'); + #check_nothing_installed(); + + urpmi('a c'); + check_installed_and_remove('a', 'c'); +} + +sub test_urpmi_different_transactions { + urpmi('a'); + + test_urpmi_fail('b'); + check_installed_names('a'); + + # disabled, fail when dropping RPMTAG_FILEDIGESTS + #urpmi('c'); + #check_installed_and_remove('a', 'c'); +} + +sub test_rpm_i_succeeds { + my (@rpms) = @_; + my $rpms = join(' ', map { "media/$medium_name/$_-*.rpm" } @rpms); + system_("rpm --root $::pwd/root -i $rpms"); +} +sub test_rpm_i_fail { + my (@rpms) = @_; + my $rpms = join(' ', map { "media/$medium_name/$_-*.rpm" } @rpms); + system_should_fail("rpm --root $::pwd/root -i $rpms"); +} +sub test_urpmi_fail { + my ($rpms) = @_; + system_should_fail(urpmi_cmd() . " $rpms"); +} -- cgit v1.2.1