improve code to return an empty list of packages if no packages are found

This commit is contained in:
Zach Leslie 2013-05-13 19:55:11 -07:00
parent 3057110a2c
commit 2a850eeaa5
2 changed files with 12 additions and 4 deletions

View File

@ -9,12 +9,15 @@ Puppet::Type.type(:package).provide :pkgng, :parent => Puppet::Provider::Package
def self.instances
packages = []
inst = []
begin
pkg_list = pkg(['info','-a']).lines
output = pkg(['info','-a'])
pkg_list.each do |pkgs|
pkgs = pkgs.split
if output == nil
return packages
end
output.lines.each do |line|
pkgs = line.split
pkg_info = pkgs[0].split('-')
pkg = {
:ensure => pkg_info.pop,

View File

@ -23,6 +23,11 @@ describe provider_class do
provider_class.expects(:pkg).raises(Puppet::ExecutionFailure, 'wawawa')
provider_class.instances.should be_nil
end
it "should return the empty set if no packages are listed" do
provider_class.expects(:pkg).with(['info','-a']).yields('')
provider_class.instances.should be_empty
end
end
end