Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run kitchen tests on travis #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .kitchen.docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
driver:
name: docker
52 changes: 48 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,53 @@ cache:
bundler: true
directories:
- tmp/rubocop_cache
sudo: false
sudo: true
env:
global:
- KITCHEN_LOCAL_YAML=.kitchen.docker.yml
matrix:
- TASK='rubocop'
- TASK='foodcritic'
script: bundle exec rake $TASK
- TASK='rake rubocop'
- TASK='rake foodcritic'
- TASK='kitchen test nrsysmond-default-ubuntu-1204'
- TASK='kitchen test plugin-agent-default-ubuntu-1204'
- TASK='kitchen test generic-agent-default-ubuntu-1204'
- TASK='kitchen test php-agent-default-ubuntu-1204'
- TASK='kitchen test php-external-default-ubuntu-1204'
- TASK='kitchen test nrsysmond-default-ubuntu-1404'
- TASK='kitchen test plugin-agent-default-ubuntu-1404'
- TASK='kitchen test generic-agent-default-ubuntu-1404'
- TASK='kitchen test php-agent-default-ubuntu-1404'
- TASK='kitchen test php-external-default-ubuntu-1404'
- TASK='kitchen test nrsysmond-default-ubuntu-1604'
- TASK='kitchen test plugin-agent-default-ubuntu-1604'
- TASK='kitchen test generic-agent-default-ubuntu-1604'
- TASK='kitchen test php-agent-default-ubuntu-1604'
- TASK='kitchen test php-external-default-ubuntu-1604'
- TASK='kitchen test nrsysmond-default-debian-79'
- TASK='kitchen test plugin-agent-default-debian-79'
- TASK='kitchen test generic-agent-default-debian-79'
- TASK='kitchen test php-agent-default-debian-79'
- TASK='kitchen test php-external-default-debian-79'
- TASK='kitchen test nrsysmond-default-debian-84'
- TASK='kitchen test plugin-agent-default-debian-84'
- TASK='kitchen test generic-agent-default-debian-84'
- TASK='kitchen test php-agent-default-debian-84'
- TASK='kitchen test php-external-default-debian-84'
- TASK='kitchen test nrsysmond-default-centos-67'
- TASK='kitchen test plugin-agent-default-centos-67'
- TASK='kitchen test generic-agent-default-centos-67'
- TASK='kitchen test php-agent-default-centos-67'
- TASK='kitchen test php-external-default-centos-67'
- TASK='kitchen test nrsysmond-default-centos-72'
- TASK='kitchen test plugin-agent-default-centos-72'
- TASK='kitchen test generic-agent-default-centos-72'
- TASK='kitchen test php-agent-default-centos-72'
- TASK='kitchen test php-external-default-centos-72'

before_script:
- source <(curl -sL https://raw.githubusercontent.com/zuazo/kitchen-in-travis/0.5.0/scripts/start_docker.sh)

script:
- bundle exec $TASK
Copy link
Contributor

@jeffbyrnes jeffbyrnes Jul 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you rewrote this like so:

env:
  matrix:
    - SUITE='generic-agent-default-centos-72'
    - SUITE='php-agent-default-centos-72'
    - SUITE='php-external-default-centos-72'

script:
- rake rubocop
- rake foodcritic .
- bundle exec kitchen test $SUITE

DRY things up a bit.

Also as I mentioned you can just install ChefDK using APT, and then your script could be:

script:
- cookstyle
- foodcritic .
- kitchen test $SUITE

Best part of cookstyle is that it uses a slower-moving, Chef-centric set of Rubocop rules, so your tests won’t break just because Rubocop was updated & has new rules to follow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am inclined to avoid coupling different test types inside the same CI task as it makes them harder to use IMHO.

If you want to slow down package updates, you can be more strict with versions inside the Gemfile and/or include the .lock file into the repo.
http://bundler.io/

If your concerned about the starting prefix of TASK, we can probably introduce some Rakfile magic..
http://stackoverflow.com/questions/9539324/generate-rake-test-tasks-dynamically-based-on-existing-test-files-in-a-rakefil
I know you prefer to move away from it...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ofir-petrushka ahh, I see. Yeah, makes total sense to have the RuboCop & Foodcritic linting run as their own sub-builds. Worth the lack of DRY-ness.

As for “slow down package updates”, it’s not about that. The whole point of ChefDK is to provide a sensible, compatible environment as a package appropriate for developing using Chef. If you take a look at ChefCo’s own cookbooks, this is how they test, which I take as a strong recommendation: sous-chefs/mysql@b59be78


after_failure: cat docker_daemon.log
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ gem 'berkshelf'

group :integration do
gem 'test-kitchen'
end

group :vagrant do
gem 'vagrant-wrapper'
gem 'kitchen-vagrant'
end

Expand All @@ -12,3 +16,7 @@ group :development, :test do
gem 'rubocop'
gem 'foodcritic'
end

group :docker do
gem 'kitchen-docker', '~> 2.1.0'
end
38 changes: 38 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,41 @@ def prepare_foodcritic_sandbox(sandbox)
cp_r Dir.glob("{#{files.join(',')}}"), sandbox
puts "\n\n"
end

desc 'Run Test Kitchen integration tests'
namespace :integration do
# Gets a collection of instances.
#
# @param regexp [String] regular expression to match against instance names.
# @param config [Hash] configuration values for the `Kitchen::Config` class.
# @return [Collection<Instance>] all instances.
def kitchen_instances(regexp, config)
instances = Kitchen::Config.new(config).instances
return instances if regexp.nil? || regexp == 'all'
instances.get_all(Regexp.new(regexp))
end

# Runs a test kitchen action against some instances.
#
# @param action [String] kitchen action to run (defaults to `'test'`).
# @param regexp [String] regular expression to match against instance names.
# @param loader_config [Hash] loader configuration options.
# @return void
def run_kitchen(action, regexp, loader_config = {})
action = 'test' if action.nil?
require 'kitchen'
Kitchen.logger = Kitchen.default_file_logger
config = { loader: Kitchen::Loader::YAML.new(loader_config) }
kitchen_instances(regexp, config).each { |i| i.send(action) }
end

desc 'Run integration tests with kitchen-vagrant'
task :vagrant, [:regexp, :action] do |_t, args|
run_kitchen(args.action, args.regexp)
end

desc 'Run integration tests with kitchen-docker'
task :docker, [:regexp, :action] do |_t, args|
run_kitchen(args.action, args.regexp, local_config: '.kitchen.docker.yml')
end
end