module RSpec::Puppet::Augeas::Fixtures
Public Instance Methods
apply(resource, logs)
click to toggle source
Runs a particular resource via a catalog and stores logs in the caller’s supplied array
# File lib/rspec-puppet-augeas/fixtures.rb, line 38 def apply(resource, logs) logs.clear Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(logs)) Puppet::Util::Log.level = 'debug' confdir = Dir.mktmpdir oldconfdir = Puppet[:confdir] Puppet[:confdir] = confdir [:require, :before, :notify, :subscribe].each { |p| resource.delete p } catalog = Puppet::Resource::Catalog.new catalog.add_resource resource catalog = catalog.to_ral if resource.is_a? Puppet::Resource txn = catalog.apply Puppet::Util::Log.close_all txn ensure if confdir Puppet[:confdir] = oldconfdir FileUtils.rm_rf(confdir) end end
load_fixtures(resource, file) { |dir| ... }
click to toggle source
Copies test fixtures to a temporary directory If file is nil, copies the entire augeas_fixtures directory If file is a hash, it copies the “value” from augeas_fixtures
to each "key" path
# File lib/rspec-puppet-augeas/fixtures.rb, line 11 def load_fixtures(resource, file) if block_given? Dir.mktmpdir("rspec-puppet-augeas") do |dir| prepare_fixtures(dir, resource, file) yield dir end else dir = Dir.mktmpdir("rspec-puppet-augeas") prepare_fixtures(dir, resource, file) dir end end
prepare_fixtures(dir, resource, file)
click to toggle source
# File lib/rspec-puppet-augeas/fixtures.rb, line 24 def prepare_fixtures(dir, resource, file) if file.nil? FileUtils.cp_r File.join(RSpec.configuration.augeas_fixtures, "."), dir else file.each do |dest,src| FileUtils.mkdir_p File.join(dir, File.dirname(dest)) src = File.join(RSpec.configuration.augeas_fixtures, src) unless src.start_with? File::SEPARATOR FileUtils.cp_r src, File.join(dir, dest) end end end