module Chef::DSL::Audit

Public Instance Methods

control_group(*args, &block) click to toggle source

Can encompass tests in a `control` block or `describe` block Adds the controls group and block (containing controls to execute) to the runner's list of pending examples

# File lib/chef/dsl/audit.rb, line 27
def control_group(*args, &block)
  raise Chef::Exceptions::NoAuditsProvided unless block

  name = args[0]
  if name.nil? || name.empty?
    raise Chef::Exceptions::AuditNameMissing
  elsif run_context.audits.has_key?(name)
    raise Chef::Exceptions::AuditControlGroupDuplicate.new(name)
  end

  # This DSL will only work in the Recipe class because that exposes the cookbook_name
  cookbook_name = self.cookbook_name
  metadata = {
      cookbook_name: cookbook_name,
      cookbook_version: run_context.cookbook_collection[cookbook_name].version,
      recipe_name: recipe_name,
      line_number: block.source_location[1],
  }

  run_context.audits[name] = Struct.new(:args, :block, :metadata).new(args, block, metadata)
end