Skip to content

Commit dc28505

Browse files
committed
Add tests for -noarch
Commit 3a54851 detected cases where the "architecture was in the title of a package and moves it to the end of the version string" such as ".86_64" But the noarch regex matched any occurrence "noarch", including "-noarch". That bug was fixed in commit ca36fc6. This commit adds some missing tests and refactors the regex.
1 parent 47f7f3b commit dc28505

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lib/puppet/util/rpm_compare.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Puppet::Util::RpmCompare
77
armv5tejl armv6l armv7l m68kmint s390 s390x ia64 x86_64 sh3 sh4
88
].freeze
99

10-
ARCH_REGEX = Regexp.new('\.' + ARCH_LIST.join('|\.'))
10+
ARCH_REGEX = Regexp.new(ARCH_LIST.map { |arch| "\\.#{arch}" }.join('|'))
1111

1212
# This is an attempt at implementing RPM's
1313
# lib/rpmvercmp.c rpmvercmp(a, b) in Ruby.

spec/shared_examples/rhel_package_provider.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@
172172
allow(arch_provider).to receive(:query).and_return(:ensure => version)
173173
arch_provider.install
174174
end
175+
176+
it "does not move '-noarch' to the end of version" do
177+
version = '1.2.3'
178+
resource = Puppet::Type.type(:package).new(
179+
:name => "#{name}-noarch",
180+
:ensure => version,
181+
:provider =>provider_name
182+
)
183+
expect(Puppet::Util::Execution).to receive(:execute).with(["/usr/bin/#{provider_name}", '-d', '0', '-e', error_level, '-y', :install, "#{name}-noarch-#{version}"])
184+
provider = provider_class.new
185+
provider.resource = resource
186+
allow(provider).to receive(:query).and_return(:ensure => version)
187+
provider.install
188+
end
175189
end
176190

177191
describe 'when uninstalling' do

spec/unit/util/rpm_compare_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ class RpmTest
172172
expect([version[:epoch], version[:version], version[:release]]).to \
173173
eq([nil, '2.2', 'SNAPSHOT20121119105647'])
174174
end
175+
176+
it 'parses .noarch' do
177+
version = RpmTest.rpm_parse_evr('3.0.12-1.el5.centos.noarch')
178+
expect(version[:arch]).to eq('noarch')
179+
end
175180
end
176181

177182
describe '.compare_values' do

0 commit comments

Comments
 (0)