Chef/inspec with testing auto-runner


#1

Hi there,

I just wonder is there some tools like Guard gem compatible with chef/inspec (https://github.com/guard/guard).
Guard is configured with a Guardfile that tells it which directories and files to monitor, and what command to run when they change.

So I’d love to run a test suite when spec files are changed.
Do you know any tools like this?


#2

InSpec is going to work with “real” machines, but I see this plugin for
Guard and Test Kitchen (2013!)
https://rubygems.org/gems/guard-kitchen

“kitchen verify” with your verifier set to inspec would work, no experience
with Guard myself though.

Thanks,
Matt Ray
Manager, Solutions Architect - APJ :: Chef
matt@chef.io
AUS: +61 457 231 372
US: +1 512 731 2218
mattray :: GitHub :: IRC :: Slack :: Twitter


#3

The Guard project definitely will definitely work. Consider using guard-shell. It’s generic and when file events are generated you can run a command on that particular file or the entire profile.

$ guard init shell

~/myprofile/Guardfile

command = "inspec exec"
target = "-t TARGET_INSTANCE"

guard :shell do
  watch /controls\/.+\.rb/ do |m|
    m[0] + " has changed."
    `#{command} #{m[0]} #{target}`
  end

  watch /inspec\.yml/ do
     `#{command} . #{target}`
  end
end

The first guard will check to see if a Ruby file within the controls directory changed. If it does execute the command inspec exec control/FILENAME.rb -t TARGET_INSTANCE. The second guard will watch to see if the `inspec.yml’ file changes and run the entire profile.

This could be refined a bit but I think this hopefully conveys an approach.