tdd - Testing Chef roles and environments -
i'm new chef , have been using test kitchen test validity of cookbooks, works great. i'm trying ensure environment-specific attributes correct on production nodes prior running chef initially. these defined in role.
for example, may have recipes converge using vagrant box dev settings, validates cookbook. want able test production node's role. think want these tests source of truth describing environment. looking @ test kitchen's documentation, seems beyond scope.
is assumption correct? there better approach test cookbook before first time chef run on production node ensure has correct settings?
i pleasantly discovered chef_zero uses "test/integration" directory it's chef repository.
just create roles under
- test/integration/roles
example
standard chef cookbook layout.
├── attributes │ └── default.rb ├── berksfile ├── berksfile.lock ├── chefignore ├── .kitchen.yml ├── metadata.rb ├── readme.md ├── recipes │ └── default.rb └── test └── integration ├── default │ └── serverspec │ ├── default_spec.rb │ └── spec_helper.rb └── roles └── demo.json
.kitchen.yml
--- driver: name: vagrant provisioner: name: chef_zero platforms: - name: ubuntu-14.04 suites: - name: default run_list: - role[demo] attributes:
notes:
- provisioner chef_zero
- the runlist configured use role
recipes/default.rb
file "/opt/helloworld.txt" content "#{node['demo']['greeting']}" end
attributes/default.rb
default['demo']['greeting'] = "hello world"
notes:
- cookbook won't compile without default
test/integration/default/serverspec/default_spec.rb
require 'spec_helper' describe file('/opt/helloworld.txt') { should be_file } its(:content) { should match /this came role/ } end
notes:
- integration test looking content set role attribute
test/integration/roles/demo.json
{ "name": "demo", "default_attributes": { "demo": { "greeting": "this came role" } }, "run_list": [ "recipe[demo]" ] }