Merge branch '4.x'

* 4.x:
  (#14670) Fixup file_line autorequire specs
  (#14670) autorequire a file_line resource's path
This commit is contained in:
Jeff McCune 2012-11-26 11:41:34 -08:00
commit 06952967bf
2 changed files with 23 additions and 0 deletions

View file

@ -50,6 +50,11 @@ Puppet::Type.newtype(:file_line) do
end
end
# Autorequire the file resource if it's being managed
autorequire(:file) do
self[:path]
end
validate do
unless self[:line] and self[:path]
raise(Puppet::Error, "Both line and path are required attributes")

View file

@ -48,4 +48,22 @@ describe Puppet::Type.type(:file_line) do
it 'should default to ensure => present' do
file_line[:ensure].should eq :present
end
it "should autorequire the file it manages" do
catalog = Puppet::Resource::Catalog.new
file = Puppet::Type.type(:file).new(:name => "/tmp/path")
catalog.add_resource file
catalog.add_resource file_line
relationship = file_line.autorequire.find do |rel|
(rel.source.to_s == "File[/tmp/path]") and (rel.target.to_s == file_line.to_s)
end
relationship.should be_a Puppet::Relationship
end
it "should not autorequire the file it manages if it is not managed" do
catalog = Puppet::Resource::Catalog.new
catalog.add_resource file_line
file_line.autorequire.should be_empty
end
end