diff options
author | Scott Hain <elejia@gmail.com> | 2014-06-17 16:41:37 -0700 |
---|---|---|
committer | Scott Hain <elejia@gmail.com> | 2014-06-17 16:41:37 -0700 |
commit | fe076d0a7180b9d67b8606b197acd245a2318bc4 (patch) | |
tree | bd338db177c5714b5962c51d2ce8c77e95c60d4d | |
parent | 4c4a5d8bb9ab59d392e867e4fb82eb7aefe57bc3 (diff) | |
parent | 2d16254da21fee985b6b01fc59dade436b9743d3 (diff) | |
download | chef-fe076d0a7180b9d67b8606b197acd245a2318bc4.tar.gz |
Merge pull request #1501 from opscode/shain/rpm_version_regex
Updated tests with more complicated data, fixed regex
-rw-r--r-- | lib/chef/provider/package/rpm.rb | 4 | ||||
-rw-r--r-- | spec/unit/provider/package/rpm_spec.rb | 70 |
2 files changed, 37 insertions, 37 deletions
diff --git a/lib/chef/provider/package/rpm.rb b/lib/chef/provider/package/rpm.rb index 2aa4e01e68..74baddb062 100644 --- a/lib/chef/provider/package/rpm.rb +++ b/lib/chef/provider/package/rpm.rb @@ -60,7 +60,7 @@ class Chef status = popen4("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}") do |pid, stdin, stdout, stderr| stdout.each do |line| case line - when /([\w\d_.-]+)\s([\w\d_.-]+)/ + when /([\w\d+_.-]+)\s([\w\d_.-]+)/ @current_resource.package_name($1) @new_resource.version($2) @candidate_version = $2 @@ -78,7 +78,7 @@ class Chef @rpm_status = popen4("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@current_resource.package_name}") do |pid, stdin, stdout, stderr| stdout.each do |line| case line - when /([\w\d_.-]+)\s([\w\d_.-]+)/ + when /([\w\d+_.-]+)\s([\w\d_.-]+)/ Chef::Log.debug("#{@new_resource} current version is #{$2}") @current_resource.version($2) end diff --git a/spec/unit/provider/package/rpm_spec.rb b/spec/unit/provider/package/rpm_spec.rb index adb829ced3..50e6528317 100644 --- a/spec/unit/provider/package/rpm_spec.rb +++ b/spec/unit/provider/package/rpm_spec.rb @@ -24,8 +24,8 @@ describe Chef::Provider::Package::Rpm do @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) - @new_resource = Chef::Resource::Package.new("emacs") - @new_resource.source "/tmp/emacs-21.4-20.el5.i386.rpm" + @new_resource = Chef::Resource::Package.new("ImageMagick-c++") + @new_resource.source "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm" @provider = Chef::Provider::Package::Rpm.new(@new_resource, @run_context) @@ -38,13 +38,13 @@ describe Chef::Provider::Package::Rpm do it "should create a current resource with the name of new_resource" do @provider.stub(:popen4).and_return(@status) @provider.load_current_resource - @provider.current_resource.name.should == "emacs" + @provider.current_resource.name.should == "ImageMagick-c++" end it "should set the current reource package name to the new resource package name" do @provider.stub(:popen4).and_return(@status) @provider.load_current_resource - @provider.current_resource.package_name.should == 'emacs' + @provider.current_resource.package_name.should == 'ImageMagick-c++' end it "should raise an exception if a source is supplied but not found" do @@ -53,24 +53,24 @@ describe Chef::Provider::Package::Rpm do end it "should get the source package version from rpm if provided" do - @stdout = StringIO.new("emacs 21.4-20.el5") - @provider.should_receive(:popen4).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' /tmp/emacs-21.4-20.el5.i386.rpm").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - @provider.should_receive(:popen4).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' emacs").and_return(@status) + @stdout = StringIO.new("ImageMagick-c++ 6.5.4.7-7.el6_5") + @provider.should_receive(:popen4).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.should_receive(:popen4).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' ImageMagick-c++").and_return(@status) @provider.load_current_resource - @provider.current_resource.package_name.should == "emacs" - @provider.new_resource.version.should == "21.4-20.el5" + @provider.current_resource.package_name.should == "ImageMagick-c++" + @provider.new_resource.version.should == "6.5.4.7-7.el6_5" end it "should return the current version installed if found by rpm" do - @stdout = StringIO.new("emacs 21.4-20.el5") - @provider.should_receive(:popen4).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' /tmp/emacs-21.4-20.el5.i386.rpm").and_return(@status) - @provider.should_receive(:popen4).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' emacs").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @stdout = StringIO.new("ImageMagick-c++ 6.5.4.7-7.el6_5") + @provider.should_receive(:popen4).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm").and_return(@status) + @provider.should_receive(:popen4).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' ImageMagick-c++").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @provider.current_resource.version.should == "21.4-20.el5" + @provider.current_resource.version.should == "6.5.4.7-7.el6_5" end it "should raise an exception if the source is not set but we are installing" do - new_resource = Chef::Resource::Package.new("emacs") + new_resource = Chef::Resource::Package.new("ImageMagick-c++") provider = Chef::Provider::Package::Rpm.new(new_resource, @run_context) lambda { provider.run_action(:any) }.should raise_error(Chef::Exceptions::Package) end @@ -84,64 +84,64 @@ describe Chef::Provider::Package::Rpm do describe "after the current resource is loaded" do before do - @current_resource = Chef::Resource::Package.new("emacs") + @current_resource = Chef::Resource::Package.new("ImageMagick-c++") @provider.current_resource = @current_resource end describe "when installing or upgrading" do it "should run rpm -i with the package source to install" do @provider.should_receive(:run_command_with_systems_locale).with({ - :command => "rpm -i /tmp/emacs-21.4-20.el5.i386.rpm" + :command => "rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm" }) - @provider.install_package("emacs", "21.4-20.el5") + @provider.install_package("ImageMagick-c++", "6.5.4.7-7.el6_5") end it "should run rpm -U with the package source to upgrade" do @current_resource.version("21.4-19.el5") @provider.should_receive(:run_command_with_systems_locale).with({ - :command => "rpm -U /tmp/emacs-21.4-20.el5.i386.rpm" + :command => "rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm" }) - @provider.upgrade_package("emacs", "21.4-20.el5") + @provider.upgrade_package("ImageMagick-c++", "6.5.4.7-7.el6_5") end it "should install package if missing and set to upgrade" do - @current_resource.version("emacs") + @current_resource.version("ImageMagick-c++") @provider.should_receive(:run_command_with_systems_locale).with({ - :command => "rpm -U /tmp/emacs-21.4-20.el5.i386.rpm" + :command => "rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm" }) - @provider.upgrade_package("emacs", "21.4-20.el5") + @provider.upgrade_package("ImageMagick-c++", "6.5.4.7-7.el6_5") end it "should install from a path when the package is a path and the source is nil" do - @new_resource = Chef::Resource::Package.new("/tmp/emacs-21.4-20.el5.i386.rpm") + @new_resource = Chef::Resource::Package.new("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") @provider = Chef::Provider::Package::Rpm.new(@new_resource, @run_context) - @new_resource.source.should == "/tmp/emacs-21.4-20.el5.i386.rpm" - @current_resource = Chef::Resource::Package.new("emacs") + @new_resource.source.should == "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm" + @current_resource = Chef::Resource::Package.new("ImageMagick-c++") @provider.current_resource = @current_resource @provider.should_receive(:run_command_with_systems_locale).with({ - :command => "rpm -i /tmp/emacs-21.4-20.el5.i386.rpm" + :command => "rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm" }) - @provider.install_package("/tmp/emacs-21.4-20.el5.i386.rpm", "21.4-20.el5") + @provider.install_package("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", "6.5.4.7-7.el6_5") end it "should uprgrade from a path when the package is a path and the source is nil" do - @new_resource = Chef::Resource::Package.new("/tmp/emacs-21.4-20.el5.i386.rpm") + @new_resource = Chef::Resource::Package.new("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") @provider = Chef::Provider::Package::Rpm.new(@new_resource, @run_context) - @new_resource.source.should == "/tmp/emacs-21.4-20.el5.i386.rpm" - @current_resource = Chef::Resource::Package.new("emacs") + @new_resource.source.should == "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm" + @current_resource = Chef::Resource::Package.new("ImageMagick-c++") @current_resource.version("21.4-19.el5") @provider.current_resource = @current_resource @provider.should_receive(:run_command_with_systems_locale).with({ - :command => "rpm -U /tmp/emacs-21.4-20.el5.i386.rpm" + :command => "rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm" }) - @provider.upgrade_package("/tmp/emacs-21.4-20.el5.i386.rpm", "21.4-20.el5") + @provider.upgrade_package("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", "6.5.4.7-7.el6_5") end it "installs with custom options specified in the resource" do @provider.candidate_version = '11' @new_resource.options("--dbpath /var/lib/rpm") @provider.should_receive(:run_command_with_systems_locale).with({ - :command => "rpm --dbpath /var/lib/rpm -i /tmp/emacs-21.4-20.el5.i386.rpm" + :command => "rpm --dbpath /var/lib/rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm" }) @provider.install_package(@new_resource.name, @provider.candidate_version) end @@ -150,9 +150,9 @@ describe Chef::Provider::Package::Rpm do describe "when removing the package" do it "should run rpm -e to remove the package" do @provider.should_receive(:run_command_with_systems_locale).with({ - :command => "rpm -e emacs-21.4-20.el5" + :command => "rpm -e ImageMagick-c++-6.5.4.7-7.el6_5" }) - @provider.remove_package("emacs", "21.4-20.el5") + @provider.remove_package("ImageMagick-c++", "6.5.4.7-7.el6_5") end end end |