add a Rakefile to structure test runs
Having a Rakefile will allow us to change the actual test commands on our side rather than relying on changes to the openstack-infra repository. This should make it a lot faster to change things, but also easier to test since the jenkins jobs are actually run in this repository, not the openstack-infra one. This commit defines the jobs we previously had defined in Jenkins and uses 'high-level' naming consistently (i.e. lint, style vs. foodcritic, rubocop). There is also a :clean task to help with deleting the files generated by the other jobs. Also changed foodcritic to run on the source cookbook rather than the one installed by berks, see e.g. https://github.com/berkshelf/berkshelf/issues/931#issuecomment-29668369 Change-Id: Id085444027efd90049508abe6a309fed7dfffee8 blueprint: rakefile
This commit is contained in:
parent
9e853b2707
commit
996176b178
|
@ -1,5 +1,5 @@
|
|||
.bundle/
|
||||
.cookbooks/
|
||||
berks-cookbooks/
|
||||
.kitchen
|
||||
.vagrant
|
||||
.coverage/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
AllCops:
|
||||
Includes:
|
||||
Include:
|
||||
- metadata.rb
|
||||
- Gemfile
|
||||
- attributes/**
|
||||
|
@ -8,6 +8,8 @@ AllCops:
|
|||
- recipes/**
|
||||
- resources/**
|
||||
- spec/**
|
||||
Exclude:
|
||||
- berks-cookbooks/**
|
||||
|
||||
Encoding:
|
||||
Exclude:
|
||||
|
|
2
Gemfile
2
Gemfile
|
@ -2,8 +2,8 @@ source 'https://rubygems.org'
|
|||
|
||||
gem 'chef', '~> 11.16'
|
||||
gem 'json', '<= 1.7.7' # chef 11 dependency
|
||||
gem 'strainer'
|
||||
gem 'berkshelf', '~> 3.1.5'
|
||||
gem 'chefspec', '~> 4.0.0'
|
||||
gem 'foodcritic', '~> 4.0'
|
||||
gem 'rubocop', '~> 0.18.1'
|
||||
gem 'rake', '~> 10.0'
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
task default: ["test"]
|
||||
|
||||
task :test => [:lint, :style, :knife, :unit]
|
||||
|
||||
task :bundler_prep do
|
||||
mkdir_p '.bundle'
|
||||
sh %{bundle install --path=.bundle --jobs 1 --retry 3 --verbose}
|
||||
end
|
||||
|
||||
task :berks_prep => :bundler_prep do
|
||||
sh %{bundle exec berks vendor}
|
||||
end
|
||||
|
||||
task :lint => :bundler_prep do
|
||||
sh %{bundle exec foodcritic --epic-fail any --tags ~FC003 --tags ~FC023 .}
|
||||
end
|
||||
|
||||
task :knife => :bundler_prep do
|
||||
sh %{bundle exec knife cookbook test openstack-integration-test -o berks-cookbooks}
|
||||
end
|
||||
|
||||
task :style => :bundler_prep do
|
||||
sh %{bundle exec rubocop}
|
||||
end
|
||||
|
||||
task :unit => :berks_prep do
|
||||
sh %{bundle exec rspec --format documentation}
|
||||
end
|
||||
|
||||
task :clean do
|
||||
rm_rf [
|
||||
'.bundle',
|
||||
'berks-cookbooks',
|
||||
'Gemfile.lock',
|
||||
'Berksfile.lock'
|
||||
]
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
# Strainerfile
|
||||
rubocop: rubocop $SANDBOX/$COOKBOOK
|
||||
knife test: knife cookbook test $COOKBOOK
|
||||
foodcritic: foodcritic -f any -t ~FC003 -t ~FC023 $SANDBOX/$COOKBOOK
|
||||
chefspec: rspec $SANDBOX/$COOKBOOK/spec
|
18
TESTING.md
18
TESTING.md
|
@ -1,18 +1,20 @@
|
|||
# Testing the Cookbook #
|
||||
|
||||
This cookbook uses [bundler](http://gembundler.com/), [berkshelf](http://berkshelf.com/), and [strainer](https://github.com/customink/strainer) to isolate dependencies and run tests.
|
||||
This cookbook uses [bundler](http://gembundler.com/) and [berkshelf](http://berkshelf.com/) to isolate dependencies.
|
||||
Make sure you have `ruby 1.9.x`, `bundler`, `rake`, build essentials and the header files for `gecode` installed before continuing. Make sure that you're using gecode version 3. More info [here](https://github.com/opscode/dep-selector-libgecode/tree/0bad63fea305ede624c58506423ced697dd2545e#using-a-system-gecode-instead).
|
||||
|
||||
Tests are defined in [Strainerfile](Strainerfile), which in turn calls rubocop, knife, foodcritic and chefspec.
|
||||
We have four test suites which you can run either, individually (there are three rake tasks):
|
||||
|
||||
To run all of the tests with Strainer:
|
||||
$ rake lint
|
||||
$ rake style
|
||||
$ rake knife
|
||||
$ rake unit
|
||||
|
||||
$ bundle exec strainer test -s Strainerfile
|
||||
or altogether:
|
||||
|
||||
Or you may run the tests individually:
|
||||
$ rake test
|
||||
|
||||
$ bundle install --path=.bundle # install gem dependencies
|
||||
$ bundle exec berks vendor .cookbooks # install cookbook dependencies and create the folder .cookbooks
|
||||
$ bundle exec strainer test -s Strainerfile # run tests
|
||||
The `rake` tasks will take care of installing the needed gem dependencies and cookbooks with `berkshelf`.
|
||||
|
||||
## Rubocop ##
|
||||
|
||||
|
|
Loading…
Reference in New Issue