Last active
January 4, 2016 00:48
-
-
Save fatmcgav/8543743 to your computer and use it in GitHub Desktop.
File.exists? type testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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