0
votes

I'm learning chef and working with test kitchen. I have written a plugin script that checks if any *.core files in /var/tmp/ in my test instances were altered less than 5 min ago. In my cookbook this file is $COOKBOOK_ROOT_DIR/files/default/plugins/check_core_files.sh:

I have noticed that kitchen delivers my script into two locations on my instances (the location is also the same on my centos 6 and ubuntu test instances):

[root@default-centos-71 vagrant]# find / -name check_core_files.sh
/tmp/kitchen/cookbooks/$COOKBOOKNAME/files/default/plugins/check_core_files.sh
/tmp/kitchen/cache/cookbooks/$COOKBOOKNAME/files/default/plugins/check_core_files.sh

I would like to run this with the describe command function in $COOKBOOK_ROOT_DIR/test/integration/default/serverspec/default_spec.rb by adding the following to the file:

describe command("#{PATH_TO_SCRIPT}/check_core_files.sh") do
  its(:exit_status) { should eq 0 }  # checks if there are *.core files in /var/tmp/ less than 5 min old
end

Is there a default variable I should be using to get this path? Or do I need to specify the exact path to get to my plugin script to run? Since the plugin script is present in two locations, which one should be used? Or does it not matter?

1

1 Answers

1
votes

Those are both temporary cache files. You need to use a cookbook_file resource to write the file out to a known location under your control and then have the test check that. Testing against Chef's internal structures is, as you might imagine, unsupported :)