Skip to content

Instantly share code, notes, and snippets.

@fatmcgav
Last active January 4, 2016 00:48
Show Gist options
  • Save fatmcgav/8543743 to your computer and use it in GitHub Desktop.
Save fatmcgav/8543743 to your computer and use it in GitHub Desktop.
File.exists? type testing
Puppet::Type.newtype(:domain) do
@doc = "Manage Glassfish domains"
ensurable
...
newparam(:passwordfile) do
desc "The file containing the password for the user."
validate do |value|
unless File.exists? value
raise ArgumentError, "%s does not exist" % value
end
end
end
...
end
require 'spec_helper'
describe Puppet::Type.type(:domain) do
before :each do
described_class.stubs(:defaultprovider).returns providerclass
end
let :providerclass do
described_class.provide(:fake_domain_provider) { mk_resource_methods }
end
...
describe "for passwordfile" do
it "should support a valid file path" do
#File.stubs(:exists?).with('/tmp/asadmin.pass').returns(:true)
File.expects(:exists?).with('/tmp/asadmin.pass').returns(true).once
described_class.new(:domainname => 'domain', :passwordfile => '/tmp/asadmin.pass')[:passwordfile].should == '/tmp/asadmin.pass'
end
it "should fail an invalid file path" do
#File.stubs(:exists?).with('/tmp/nonexistent').returns(:false)
File.expects(:exists?).with('/tmp/nonexistent').returns(false).once
expect { described_class.new(:domainname => 'domain', :passwordfile => '/tmp/nonexistent') }.to raise_error(Puppet::Error, /does not exist/)
end
end
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment