I happily discovered that chef_zero uses the "test / integration" directory as the chef repository.
Just create your roles in
- Test / Integration / Roles
Example
Chef's standard cookbook.
βββ 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 is chef_zero
- The execution list is configured to use the role
Recipes /default.rb
file "/opt/helloworld.txt" do content "#{node['demo']['greeting']}" end
attributes /default.rb
default['demo']['greeting'] = "hello world"
Notes:
- Cookbook will not compile without using default
Test / integration / default / serverspec / default _spec.rb
require 'spec_helper' describe file('/opt/helloworld.txt') do it { should be_file } its(:content) { should match /this came from my role/ } end
Notes:
- Integration test validates content specified by role attribute
Test / integration / roles / demo.json
{ "name": "demo", "default_attributes": { "demo": { "greeting": "this came from my role" } }, "run_list": [ "recipe[demo]" ] }
Mark o'connor
source share