1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
require 'spec_helper'
require 'puppet/file_bucket/dipper'
describe "Nagios file creation" do
include PuppetSpec::Files
let(:initial_mode) { 0600 }
before :each do
FileUtils.touch(target_file)
Puppet::FileSystem.chmod(initial_mode, target_file)
allow_any_instance_of(Puppet::FileBucket::Dipper).to receive(:backup) # Don't backup to filebucket
end
let :target_file do
tmpfile('nagios_integration_specs')
end
# Copied from the crontab integration spec.
#
# @todo This should probably live in the PuppetSpec module instead then.
def run_in_catalog(*resources)
catalog = Puppet::Resource::Catalog.new
catalog.host_config = false
resources.each do |resource|
expect(resource).not_to receive(:err)
catalog.add_resource(resource)
end
# the resources are not properly contained and generated resources
# will end up with dangling edges without this stubbing:
allow(catalog).to receive(:container_of).and_return(resources[0])
catalog.apply
end
context "when creating a nagios config file" do
context "which is not managed" do
it "should choose the file mode if requested" do
resource = Puppet::Type.type(:nagios_host).new(
:name => 'spechost',
:use => 'spectemplate',
:ensure => 'present',
:target => target_file,
:mode => '0640'
)
run_in_catalog(resource)
expect_file_mode(target_file, "640")
end
end
context "which is managed" do
it "should not override the mode" do
file_res = Puppet::Type.type(:file).new(
:name => target_file,
:ensure => :present
)
nag_res = Puppet::Type.type(:nagios_host).new(
:name => 'spechost',
:use => 'spectemplate',
:ensure => :present,
:target => target_file,
:mode => '0640'
)
run_in_catalog(file_res, nag_res)
expect_file_mode(target_file, initial_mode.to_s(8))
end
end
end
end
|