Skip to content

Commit

Permalink
Merge pull request #33 from chef/integration-test
Browse files Browse the repository at this point in the history
Add integration test with test-kitchen
  • Loading branch information
srenatus committed Jan 21, 2016
2 parents aea83a7 + a46e259 commit 75ef8bb
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
/pkg/
/spec/reports/
/tmp/
test/integration/.kitchen
Berksfile.lock
33 changes: 24 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
---
sudo: required
language: ruby
cache: bundler

rvm:
- 2.2
- 2.1
- 2.0.0
- 1.9.3
- ruby-head
# necessary for docker to work
dist: trusty
services:
- docker

before_install: gem install bundler -v 1.10.6
bundler_args: --without guard
bundler_args: --without integration guard tools

sudo: false
before_install:
- gem update --system 2.4.5
- gem --version

matrix:
include:
- rvm: 1.9.3
gemfile: Gemfile
- rvm: 2.0
gemfile: Gemfile
- rvm: 2.1
gemfile: Gemfile
- rvm: ruby-head
gemfile: Gemfile
- rvm: 2.2
gemfile: Gemfile
bundler_args: --without guard tools
script: bundle exec rake test:integration
allow_failures:
- rvm: ruby-head
16 changes: 12 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ group :guard do
end

group :test do
gem 'bundler', '~> 1.5'
gem 'minitest', '~> 5.5'
gem 'rake', '~> 10'
gem 'rubocop', '~> 0.32'
gem 'concurrent-ruby', '~> 0.9'
gem 'codeclimate-test-reporter', :require => nil
gem 'test-kitchen', '~> 1.4', :require => nil
end

group :tools do
gem 'github_changelog_generator', '~> 1'
group :integration do
gem 'berkshelf'
gem 'kitchen-dokken'
end

group :development do
gem 'test-kitchen', '~> 1.4', :require => nil
group :tools do
gem 'pry', '~> 0.10'
gem 'github_changelog_generator', '~> 1'
end
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,11 @@ task :bump_version, [:version] do |_, args|
kitchen_inspec_version(v)
Rake::Task['changelog'].invoke
end

namespace :test do
task :integration do
concurrency = ENV['CONCURRENCY'] || 1
path = File.join(File.dirname(__FILE__), 'test', 'integration')
sh('sh', '-c', "cd #{path} && bundle exec kitchen test -c #{concurrency} -t .")
end
end
23 changes: 23 additions & 0 deletions lib/kitchen/verifier/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ def runner_options(transport, state = {})
runner_options_for_ssh(transport_data)
elsif transport.is_a?(Kitchen::Transport::Winrm)
runner_options_for_winrm(transport_data)
# optional transport which is not in core test-kitchen
elsif defined?(Kitchen::Transport::Dokken) && transport.is_a?(Kitchen::Transport::Dokken)
runner_options_for_docker(transport_data)
else
fail Kitchen::UserError, "Verifier #{name} does not support the #{transport.name} Transport"
end.tap do |runner_options|
Expand Down Expand Up @@ -154,6 +157,26 @@ def runner_options_for_winrm(config_data)

opts
end

# Returns a configuration Hash that can be passed to a `Inspec::Runner`.
#
# @return [Hash] a configuration hash of string-based keys
# @api private
def runner_options_for_docker(config_data)
kitchen = instance.transport.send(:connection_options, config_data).dup

opts = {
'backend' => 'docker',
'logger' => logger,
'host' => kitchen[:data_container][:Id],
'connection_timeout' => kitchen[:timeout],
'connection_retries' => kitchen[:connection_retries],
'connection_retry_sleep' => kitchen[:connection_retry_sleep],
'max_wait_until_ready' => kitchen[:max_wait_until_ready],
}

opts
end
end
end
end
24 changes: 24 additions & 0 deletions test/integration/.kitchen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
driver:
name: dokken

transport:
name: dokken

provisioner:
name: dokken

verifier:
name: inspec
sudo: true

platforms:
- name: ubuntu
driver:
image: ubuntu:14.04

suites:
- name: default
run_list:
- recipe[os_prepare]
attributes:
3 changes: 3 additions & 0 deletions test/integration/Berksfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://supermarket.chef.io'

cookbook 'os_prepare', path: './cookbooks/os_prepare'
8 changes: 8 additions & 0 deletions test/integration/cookbooks/os_prepare/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# encoding: utf-8
name 'os_prepare'
maintainer 'Chef Software, Inc.'
maintainer_email '[email protected]'
description 'This cookbook prepares the test operating systems'
version '1.0.0'
depends 'apt'
depends 'yum'
5 changes: 5 additions & 0 deletions test/integration/cookbooks/os_prepare/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# encoding: utf-8
# author: Christoph Hartmann
# author: Dominik Richter
#
# noop, do nothing
1 change: 1 addition & 0 deletions test/integration/test/integration/default/_debug_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
p "You are currently running on OS family: #{os[:family] || 'unknown'}, OS release: #{os[:release] || 'unknown'}"
7 changes: 7 additions & 0 deletions test/integration/test/integration/default/os_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# encoding: utf-8

family = os[:family]

describe os[:family] do
it { should eq family }
end

0 comments on commit 75ef8bb

Please sign in to comment.