chef-infrainspec

Possible to use Chef variables within Inspec?


I'm learning to write integration tests for my Chef cookbooks. Is it possible to reference variables from the attributes folder within my test?

Here's my test to make sure httpd and php are installed properly. However, I have additional packages I want to check for.

test/smoke/default/install.rb

%w(httpd php).each do |rpm_package|
  describe package(rpm_package) do
    it { should be_installed }
  end
end

attributes/default.rb

default['ic_apachephp']['php_packages'] = [
                              'php-mysqlnd',
                              'php-mbstring',
                              'php-gd',
                              'php-xml',
                              'php'
                            ]

Solution

  • Yes, this is possible, however not "directly". Matt Wrock described it in this blog entry.

    Necessary steps are:

    Beware that you manually have to pick from the right attribute precedence level (automatic/default/normal/override), as those are not merged.

    You can find an example of mine also in this cookbook: TYPO3-cookbooks/t3-pdns.

    EDIT: I forgot the step to tell Berkshelf about that cookbook. Add to your Berksfile:

    group :integration do
      cookbook 'export-node', path: 'test/fixtures/cookbooks/export-node'
    end