I have a WAY bigger comment block right before thi...
# puppet
g
I have a WAY bigger comment block right before this to help my team get sorted, but here's the solution I came up with, which is now in my spec_helper_local.rb:
Copy code
# 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'], # } #
Copy code
#       
# ...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 #
Copy code
#
#     -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