diff --git a/lib/puppet/provider/package/chocolatey.rb b/lib/puppet/provider/package/chocolatey.rb index 0bd5a68e..d01ad0d5 100644 --- a/lib/puppet/provider/package/chocolatey.rb +++ b/lib/puppet/provider/package/chocolatey.rb @@ -199,6 +199,7 @@ def self.instances process.each_line do |line| line.chomp! if line.empty? or line.match(/Reading environment variables.*/); next; end + raise Puppet::Error, "At least one source must be enabled." if line.match(/Unable to search for packages.*/) if choco_exe values = line.split('|') else diff --git a/spec/unit/puppet/provider/package/chocolatey_spec.rb b/spec/unit/puppet/provider/package/chocolatey_spec.rb index d29099f0..e6fa57be 100644 --- a/spec/unit/puppet/provider/package/chocolatey_spec.rb +++ b/spec/unit/puppet/provider/package/chocolatey_spec.rb @@ -473,6 +473,14 @@ :name => 'package2' } end + + it "should return nil on error" do + provider.expects(:execpipe).yields(StringIO.new(%Q(Unable to search for packages when there are no soures enabled for packages and none were passed as arguments.\n))) + + expect { + provider.instances + }.to raise_error(Puppet::Error, /At least one source must be enabled./) + end end context "with posh choco client" do