diff --git a/.gitignore b/.gitignore index 0cb6eeb..f86e0c1 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ /pkg/ /spec/reports/ /tmp/ +test/integration/.kitchen +Berksfile.lock diff --git a/.travis.yml b/.travis.yml index effcf66..acff8d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Gemfile b/Gemfile index 0ed856f..d92627e 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Rakefile b/Rakefile index a75062f..04ab755 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/lib/kitchen/verifier/inspec.rb b/lib/kitchen/verifier/inspec.rb index 99d1795..86c1ea0 100644 --- a/lib/kitchen/verifier/inspec.rb +++ b/lib/kitchen/verifier/inspec.rb @@ -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| @@ -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 diff --git a/test/integration/.kitchen.yml b/test/integration/.kitchen.yml new file mode 100644 index 0000000..a4db971 --- /dev/null +++ b/test/integration/.kitchen.yml @@ -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: diff --git a/test/integration/Berksfile b/test/integration/Berksfile new file mode 100644 index 0000000..24bb514 --- /dev/null +++ b/test/integration/Berksfile @@ -0,0 +1,3 @@ +source 'https://supermarket.chef.io' + +cookbook 'os_prepare', path: './cookbooks/os_prepare' diff --git a/test/integration/cookbooks/os_prepare/metadata.rb b/test/integration/cookbooks/os_prepare/metadata.rb new file mode 100644 index 0000000..a874318 --- /dev/null +++ b/test/integration/cookbooks/os_prepare/metadata.rb @@ -0,0 +1,8 @@ +# encoding: utf-8 +name 'os_prepare' +maintainer 'Chef Software, Inc.' +maintainer_email 'support@chef.io' +description 'This cookbook prepares the test operating systems' +version '1.0.0' +depends 'apt' +depends 'yum' diff --git a/test/integration/cookbooks/os_prepare/recipes/default.rb b/test/integration/cookbooks/os_prepare/recipes/default.rb new file mode 100644 index 0000000..72d1635 --- /dev/null +++ b/test/integration/cookbooks/os_prepare/recipes/default.rb @@ -0,0 +1,5 @@ +# encoding: utf-8 +# author: Christoph Hartmann +# author: Dominik Richter +# +# noop, do nothing diff --git a/test/integration/test/integration/default/_debug_spec.rb b/test/integration/test/integration/default/_debug_spec.rb new file mode 100644 index 0000000..cd3b41f --- /dev/null +++ b/test/integration/test/integration/default/_debug_spec.rb @@ -0,0 +1 @@ +p "You are currently running on OS family: #{os[:family] || 'unknown'}, OS release: #{os[:release] || 'unknown'}" diff --git a/test/integration/test/integration/default/os_spec.rb b/test/integration/test/integration/default/os_spec.rb new file mode 100644 index 0000000..d5503db --- /dev/null +++ b/test/integration/test/integration/default/os_spec.rb @@ -0,0 +1,7 @@ +# encoding: utf-8 + +family = os[:family] + +describe os[:family] do + it { should eq family } +end