Please review pull request #580: Ticket/2.7.x/13117 semodule broken opened by (pcarlisle)
Description:
(#13117) Fix selmodule error on each_lines
This adds a test for selmodversion_loaded (which previously had no coverage at
all) and fixes the conflicting use of readline and each_line by choosing just
one.
- Opened: Wed Mar 14 22:07:49 UTC 2012
- Based on: puppetlabs:2.7.x (e1a49621b34e468b975e5cb1e0e88e6bf47d3e08)
- Requested merge: pcarlisle:ticket/2.7.x/13117-semodule-broken (95c2b901a9d437ba9487eea4b80235ebf7bb97c1)
Diff follows:
diff --git a/lib/puppet/provider/selmodule/semodule.rb b/lib/puppet/provider/selmodule/semodule.rb
index 50ba039..d7ce77f 100644
--- a/lib/puppet/provider/selmodule/semodule.rb
+++ b/lib/puppet/provider/selmodule/semodule.rb
@@ -117,8 +117,7 @@ def selmodversion_loaded
lines = ()
begin
execpipe("#{command(:semodule)} --list") do |output|
- lines = output.readlines
- lines.each_line do |line|
+ output.each_line do |line|
line.chomp!
bits = line.split
if bits[0] == @resource[:name]
diff --git a/spec/unit/provider/package/dpkg_spec.rb b/spec/unit/provider/package/dpkg_spec.rb
index 76ec91a..4f4c32c 100755
--- a/spec/unit/provider/package/dpkg_spec.rb
+++ b/spec/unit/provider/package/dpkg_spec.rb
@@ -1,5 +1,6 @@
#!/usr/bin/env rspec
require 'spec_helper'
+require 'stringio'
provider = Puppet::Type.type(:package).provider(:dpkg)
@@ -23,7 +24,7 @@
it "should use dpkg-query" do
provider.expects(:command).with(:dpkgquery).returns "myquery"
- provider.expects(:execpipe).with("myquery -W --showformat '${Status} ${Package} ${Version}\\n'").returns @fakeresult
+ provider.expects(:execpipe).with("myquery -W --showformat '${Status} ${Package} ${Version}\\n'").yields StringIO.new(@fakeresult)
provider.instances
end
diff --git a/spec/unit/provider/package/openbsd_spec.rb b/spec/unit/provider/package/openbsd_spec.rb
index 88be790..1289c6e 100755
--- a/spec/unit/provider/package/openbsd_spec.rb
+++ b/spec/unit/provider/package/openbsd_spec.rb
@@ -1,5 +1,6 @@
#!/usr/bin/env rspec
require 'spec_helper'
+require 'stringio'
provider_class = Puppet::Type.type(:package).provider(:openbsd)
@@ -26,12 +27,12 @@ def package(args = {})
end
it "should return the empty set if no packages are listed" do
- subject.expects(:execpipe).with(%w{/bin/pkg_info -a}).yields('')
+ subject.expects(:execpipe).with(%w{/bin/pkg_info -a}).yields(StringIO.new(''))
subject.instances.should be_empty
end
it "should return all packages when invoked" do
- fixture = File.read(my_fixture('pkginfo.list'))
+ fixture = File.new(my_fixture('pkginfo.list'))
subject.expects(:execpipe).with(%w{/bin/pkg_info -a}).yields(fixture)
subject.instances.map(&:name).sort.should ==
%w{bash bzip2 expat gettext libiconv lzo openvpn python vim wget}.sort
@@ -84,7 +85,7 @@ def package(args = {})
end
it "should return the package version if in the output" do
- fixture = File.read(my_fixture('pkginfo.list'))
+ fixture = File.new(my_fixture('pkginfo.list'))
provider = subject.new(package(:name => 'bash'))
provider.expects(:execpipe).with(%w{/bin/pkg_info -I bash}).yields(fixture)
provider.get_version.should == '3.1.17'
@@ -92,7 +93,7 @@ def package(args = {})
it "should return the empty string if the package is not present" do
provider = subject.new(package(:name => 'zsh'))
- provider.expects(:execpipe).with(%w{/bin/pkg_info -I zsh}).yields('')
+ provider.expects(:execpipe).with(%w{/bin/pkg_info -I zsh}).yields(StringIO.new(''))
provider.get_version.should == ''
end
end
diff --git a/spec/unit/provider/package/pacman_spec.rb b/spec/unit/provider/package/pacman_spec.rb
index 5d9af53..fbc4bab 100755
--- a/spec/unit/provider/package/pacman_spec.rb
+++ b/spec/unit/provider/package/pacman_spec.rb
@@ -1,5 +1,6 @@
#!/usr/bin/env rspec
require 'spec_helper'
+require 'stringio'
provider = Puppet::Type.type(:package).provider(:pacman)
@@ -162,7 +163,7 @@
end
it "should return installed packages with their versions" do
- provider.expects(:execpipe).yields("package1 1.23-4\npackage2 2.00\n")
+ provider.expects(:execpipe).yields(StringIO.new("package1 1.23-4\npackage2 2.00\n"))
packages = provider.instances
packages.length.should == 2
@@ -186,7 +187,7 @@
end
it "should warn on invalid input" do
- provider.expects(:execpipe).yields("blah")
+ provider.expects(:execpipe).yields(StringIO.new("blah"))
provider.expects(:warning).with("Failed to match line blah")
provider.instances.should == []
end
diff --git a/spec/unit/provider/selmodule_spec.rb b/spec/unit/provider/selmodule_spec.rb
index 2ec6fc2..199f2ed 100755
--- a/spec/unit/provider/selmodule_spec.rb
+++ b/spec/unit/provider/selmodule_spec.rb
@@ -6,6 +6,7 @@
# 256 bytes taken from /usr/share/selinux/targeted/nagios.pp on Fedora 9
require 'spec_helper'
+require 'stringio'
provider_class = Puppet::Type.type(:selmodule).provider(:semodule)
@@ -19,19 +20,19 @@
describe "exists? method" do
it "should find a module if it is already loaded" do
@provider.expects(:command).with(:semodule).returns "/usr/sbin/semodule"
- @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields "bar\t1.2.3\nfoo\t4.4.4\nbang\t1.0.0\n"
+ @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields StringIO.new("bar\t1.2.3\nfoo\t4.4.4\nbang\t1.0.0\n")
@provider.exists?.should == :true
end
it "should return nil if not loaded" do
@provider.expects(:command).with(:semodule).returns "/usr/sbin/semodule"
- @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields "bar\t1.2.3\nbang\t1.0.0\n"
+ @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields StringIO.new("bar\t1.2.3\nbang\t1.0.0\n")
@provider.exists?.should be_nil
end
it "should return nil if no modules are loaded" do
@provider.expects(:command).with(:semodule).returns "/usr/sbin/semodule"
- @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields ""
+ @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields StringIO.new("")
@provider.exists?.should be_nil
end
end
@@ -60,7 +61,13 @@
@provider.expects(:selmodversion_loaded).returns nil
@provider.syncversion.should == :false
end
-
end
+ describe "selmodversion_loaded" do
+ it "should return the version of a loaded module" do
+ @provider.expects(:command).with(:semodule).returns "/usr/sbin/semodule"
+ @provider.expects(:execpipe).with("/usr/sbin/semodule --list").yields StringIO.new("bar\t1.2.3\nfoo\t4.4.4\nbang\t1.0.0\n")
+ @provider.selmodversion_loaded.should == "4.4.4"
+ end
+ end
end
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
