[chef] Using Attributes in a Minitest


Chronological Thread 
  • From: Jessica Bourne < >
  • To:
  • Subject: [chef] Using Attributes in a Minitest
  • Date: Mon, 4 Mar 2013 16:02:36 -0800

Hey guys,

Is there some sort of trick to using attributes in a minitest? I'm on 10.18.2.. they are just standard attributes, set in the recipe. I've tried default and set attributes, neither seem to work in the test. 

I'm basically just trying to write a test to make sure logs were rotated on Windows machines. This doesn't work:

include MiniTest::Chef::Assertions

describe 'cookbook::default' do

  time = Time.now
  log_dirs = node['cookbook']['log_dirs']

  log_dirs.each do |dir| 
    if File.directory?(dir) 
      Dir["#{dir}/*"].each do |filename|
        file = File.new(filename)
    
        it "checking mtime on #{filename}" do
            assert_modified_after(file, (time.to_i - node['cookbook']['remove_after'] * 86400))
        end
       
      end
    end
  
  end
  
end


It gives me this error when running the above recipe: NoMethodError: undefined method `[]' for nil:NilClass

But if I set log_dirs to the array of logs in the attributes file, and set remove_after to 7, it works great. I also tried removing the first attribute per this bug: https://github.com/calavera/minitest-chef-handler/issues/19 but it doesn't seem like it's picking up the node attributes within the 'it' block either. Any idea what I need to do to use those attributes in a minitest?

Jessica


  • [chef] Using Attributes in a Minitest, Jessica Bourne, 03/04/2013

Archive powered by MHonArc 2.6.16.

§