test for pkg.conf before installing

This commit is contained in:
Zach Leslie 2013-06-09 20:23:21 -07:00
parent 1a918d557f
commit 50226a3510
2 changed files with 12 additions and 3 deletions

View File

@ -39,9 +39,11 @@ Puppet::Type.type(:package).provide :pkgng, :parent => Puppet::Provider::Package
end
def install
should = @resource.should(:ensure)
cmd = ['install', '-qy', @resource[:name]]
pkg(*cmd)
if File.exists?('/usr/local/etc/pkg.conf')
pkg(['install', '-qy', resource[:name]])
else
raise Puppet::Error.new("/usr/local/etc/pkg.conf does not exist")
end
end
def uninstall

View File

@ -33,6 +33,13 @@ describe provider_class do
end
end
context "#install" do
it "should fail if pkg.conf does not exist" do
File.stub(:exist?).with('/usr/local/etc/pkg.conf') { false }
expect{ provider.install }.to raise_error(Puppet::Error, /pkg.conf does not exist/)
end
end
context "#query" do
it "should return the installed version if present" do
end