@nathenharvey
Introduction to Test Kitchen
@nathenharvey
Hello!
Nathen Harvey
VP, Community
Development
Chef
@nathenharvey
@nathenharvey
Why Testing?
• Move fast with a safety net
• Decrease feedback cycles
• Increase confidence
• Prevent regressions
• Scale
@nathenharvey
Developing Infrastructure Automation
• Write the automation
• Static analysis
• Unit testing
• Local integration testing
Create an infrastructure that matches production
Run automation
Validate results
Destroy
• Commit to version control
• Submit to pipeline
@nathenharvey
Zoom-in on Integration Testing
• Create infrastructure that matches production
• Run the automation
• Verify the results
• Destroy the infrastructure
@nathenharvey
Test Kitchen
Test harness to execute
infrastructure code on one or
more platforms in isolation.
@nathenharvey
The Test Kitchen
platforms:
- name: ubuntu-16.04
- name: centos-7
platforms
@nathenharvey
The Test Kitchen
driver:
name: vagrant
platforms:
- name: ubuntu-16.04
- name: centos-7
kitchen create driver
platforms
@nathenharvey
Zoom-in on Integration Testing
Create infrastructure that matches production
• Run the automation
• Verify the results
• Destroy the infrastructure
@nathenharvey
The Test Kitchen
driver:
name: vagrant
platforms:
- name: ubuntu-16.04
- name: centos-7
provisioner:
name: chef_zero
kitchen create driver
platforms
kitchen converge provisioner
@nathenharvey
Chef Recipe
package 'git' do
action :install
end
@nathenharvey
Zoom-in on Integration Testing
Create infrastructure that matches production
Run the automation
• Verify the results
• Destroy the infrastructure
@nathenharvey
InSpec
• Open-source framework
• Infrastructure testing
• Make assertions about state of resources in the infrastructure
@nathenharvey
Sample InSpec code
describe service('apache2') do
it { should be_running }
end
describe port(80) do
it { should be_listening }
end
describe http('http://localhost', enable_remote_worker: true) do
its('status') { should cmp 200 }
its('body') { should match /Welcome to / }
end
@nathenharvey
The Test Kitchen
driver:
name: vagrant
platforms:
- name: ubuntu-16.04
- name: centos-7
provisioner:
name: chef_zero
verifier:
name: inspec
kitchen create driver
platforms
kitchen converge provisioner
kitchen verify verifier
@nathenharvey
Verify the results with InSpec
describe package('git') do
it { should be_installed }
end
describe command('git') do
it { should exist }
end
describe command('which git') do
its('exit_status') { should eq 0 }
end
@nathenharvey
Zoom-in on Integration Testing
Create infrastructure that matches production
Run the automation
Verify the results
• Destroy the infrastructure
@nathenharvey
The Test Kitchen
driver:
name: vagrant
platforms:
- name: ubuntu-16.04
- name: centos-7
provisioner:
name: chef_zero
verifier:
name: inspec
kitchen create driver
platforms
kitchen converge provisioner
kitchen verify verifier
kitchen destroy
@nathenharvey
Zoom-in on Integration Testing
Create infrastructure that matches production
Run the automation
Verify the results
Destroy the infrastructure
@nathenharvey
The Test Kitchen
kitchen create driver
platforms
kitchen converge provisioner
kitchen verify verifier
kitchen destroy
kitchen test
@nathenharvey
The Test Kitchen
kitchen create driver
platforms
kitchen converge provisioner
kitchen verify verifier
kitchen destroy
kitchen test
kitchen destroy
@nathenharvey
The Test Kitchen
kitchen create driver
platforms
kitchen converge provisioner
kitchen verify verifier
kitchen destroy
kitchen test
kitchen destroy
kitchen create
@nathenharvey
The Test Kitchen
kitchen create driver
platforms
kitchen converge provisioner
kitchen verify verifier
kitchen destroy
kitchen test
kitchen destroy
kitchen create
kitchen converge
@nathenharvey
The Test Kitchen
kitchen create driver
platforms
kitchen converge provisioner
kitchen verify verifier
kitchen destroy
kitchen test
kitchen destroy
kitchen create
kitchen converge
kitchen verify
@nathenharvey
The Test Kitchen
kitchen create driver
platforms
kitchen converge provisioner
kitchen verify verifier
kitchen destroy
kitchen test
kitchen destroy
kitchen create
kitchen converge
kitchen verify
kitchen destroy
@nathenharvey
More Test Kitchen <3
@nathenharvey
The Test Kitchen
driver:
name: kitchen create driver
@nathenharvey
The Test Kitchen
provisioner:
name:
kitchen converge provisioner
@nathenharvey
The Test Kitchen
verifier:
name:
kitchen verify verifier
@nathenharvey
Get Started with Test Kitchen
• Install Chef Development Kit - https://downloads.chef.io/chefdk
Test Kitchen
InSpec
• Install Driver Requirements
Vagrant – VirtualBox & Vagrant
Docker – Docker
GCE – None, but best to Google Cloud SDK installed
EC2 – None, but you need an AWS account
@nathenharvey
Use, Share, Contribute!
• Test Kitchen
https://kitchen.ci/
https://github.com/test-kitchen
• InSpec
https://www.inspec.io/
https://github.com/chef/inspec
• Code from this presentation - https://github.com/nathenharvey/intro-to-test-
kitchen
@nathenharvey
Join us on Slack
• http://community-slack.chef.io
• #general (for Chef stuff)
• #test-kitchen
• #inspec
The Chef community
believes that diversity is one
of our biggest strengths!
YOU are welcome here!
@nathenharvey
What questions can I answer for you?
Nathen Harvey
VP, Community
Development
Chef
@nathenharvey

Introduction to Test Kitchen