Skip to content

Commit b55994b

Browse files
author
Jeff McCune
committed
Merge branch 'fun/2.x/14670_file_line_autorequire' into 2.x
* fun/2.x/14670_file_line_autorequire: (#14670) Fixup file_line autorequire specs (#14670) autorequire a file_line resource's path
2 parents 6c104e5 + d8cde95 commit b55994b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/puppet/type/file_line.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
end
5151
end
5252

53+
# Autorequire the file resource if it's being managed
54+
autorequire(:file) do
55+
self[:path]
56+
end
57+
5358
validate do
5459
unless self[:line] and self[:path]
5560
raise(Puppet::Error, "Both line and path are required attributes")

spec/unit/puppet/type/file_line_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,22 @@
4848
it 'should default to ensure => present' do
4949
file_line[:ensure].should eq :present
5050
end
51+
52+
it "should autorequire the file it manages" do
53+
catalog = Puppet::Resource::Catalog.new
54+
file = Puppet::Type.type(:file).new(:name => "/tmp/path")
55+
catalog.add_resource file
56+
catalog.add_resource file_line
57+
58+
relationship = file_line.autorequire.find do |rel|
59+
(rel.source.to_s == "File[/tmp/path]") and (rel.target.to_s == file_line.to_s)
60+
end
61+
relationship.should be_a Puppet::Relationship
62+
end
63+
64+
it "should not autorequire the file it manages if it is not managed" do
65+
catalog = Puppet::Resource::Catalog.new
66+
catalog.add_resource file_line
67+
file_line.autorequire.should be_empty
68+
end
5169
end

0 commit comments

Comments
 (0)