greatflyingsteve
11/15/2025, 6:43 AM# So, if you have the following Puppet manifest, in which a very cool file is exported, immediately
# collected, and also becomes a dependency for another resource:
#
# # Export this file because it's amazing and we're going to need it everywhere!
# @@file { '/etc/cool_file':
# content => 'This file is INCREDIBLY cool!',
# tags => 'extremely_cool',
# }
#
# # Collect the incredibly cool file above, and any other files we think are extremely cool
# File <<| tags == 'extremely_cool' |>>
#
# # Put a cool file in the MotD! Just gotta be sure it's there, first...
# file { '/etc/motd.d/cool_file':
# source => 'file:///etc/cool_file',
# require => File['/etc/cool_file'],
# }
# #
# ...then you can use this to make the manifest testable, like so:
#
# it 'runs an example test with simulated resource collection' do
# fake_export_collector(catalogue, exported_resources, 'File') { |attrs| attrs[:tags].include?('my_custom_tag') }
# is_expected.to contain_file('/etc/cool_file')
# end
# #
# -sr
def fake_export_collector(catalogue, exported_resources, res_type, &block)
exported_resources.call.resources.each do |res|
next unless res.type == res_type
all_attrs = res.parameters
all_attrs[:title] = res.title
all_attrs[:tags] = res.tags
catalogue.add_resource(res) if block.yield(all_attrs)
end
end