Search code examples
chef-infrainspec

Execute a command before or after an InSpec test


I wonder if anyone has or can create a sample code which demonstrates how to execute a shell script after (or before) InSpec test.

The primary idea is to use RSpec after block to clean up resources allocated during the test run.


Solution

    • Overall If you need to cleanup your machine after tests to run next batch it should different test suite or you should destroy and re-converge machine. Do you use test-kitchen for your tests?
    • If you need to do anything before InSpec test, it should be part of your converge process. Wrap your normal recipes with code which should be run before test. (preferred way).
    • You can 'hack' InSpec and provide your own sudo_command. (ugly way).