Automate Your Test Cooking

Jeff Byrnes & Eric Herot of EverTrue

Automate Your Test Cooking

Brought to you by Jeff Byrnes & Eric Herot of EverTrue

What are we trying to do?

  1. Automate testing
  2. Offload test runs
  3. Utilize freely-available resources
  4. Gain bragging rights

Really, it’s all about the bragging rights.

What do we need?

What kind of tests?

Gemfile to start

                  gem 'berkshelf',       '~> 3.1'
                  gem 'chefspec',        '~> 4.0'
                  gem 'foodcritic',      '~> 3.0'
                  gem 'test-kitchen',    '~> 1.2'
                  gem 'kitchen-vagrant', '~> 0.14'
                  gem 'kitchen-ec2',     github: 'test-kitchen/kitchen-ec2'
            

Unit Tests

                require 'spec_helper'
                 
                describe 'et_travis_demo::default' do
                  let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
                  it 'creates the file /tmp/travis_lives' do
                    expect(chef_run).to create_file '/tmp/travis_lives
                  end
                end
            

Integration Tests

Test that you got what you wanted

                describe 'Travis Test Cookbook' do
                  describe file('/tmp/travis_lives') do
                    its(:content) { should match("Some content to watch for.\n") }
                  end
                end
            

Struggles with Test Kitchen & Travis

Elephant struggling to climb a hill

Things to Know:

Don’t Panic

Test Kitchen using EC2

                driver:
                  name: ec2
                  aws_access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
                  aws_secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
                  aws_ssh_key_id: <%= ENV['AWS_KEYPAIR_NAME'] %>
                  ssh_key: <%= ENV['EC2_SSH_KEY_PATH'] %>
            

More TK Config

                driver:
                […]
                  region: us-east-1
                  availability_zone: us-east-1b
                  security_group_ids: ['ci-testing']
                  interface: public
            

More TK Config

Chef Zero helps especially if dealing with data bags.

                provisioner:
                  name: chef_zero
            

Yet More TK Config

                platforms:
                  - name: ubuntu-12.04
                    driver_config:
                      image_id: ami-36aa4d5e
                      tags:
                        Name: travis-ci-default-ubuntu-1204
                        Env: public
            

Thanks!