From 1687a25e39d164cd2f07cd5926ee09a010b67762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20Ar=C8=9B=C4=83ri=C8=99i?= Date: Tue, 30 Sep 2014 14:57:30 +0200 Subject: [PATCH] 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: Ia4d52047f1f20b4a62fd1c3726389f3ad562a968 blueprint: rakefile --- .gitignore | 2 +- .rubocop.yml | 1 + Gemfile | 1 + Rakefile | 33 +++++++++++++++++++++++++++++++++ TESTING.md | 18 +++++++++--------- 5 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 Rakefile diff --git a/.gitignore b/.gitignore index 39b1985..19577c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .bundle/ -.cookbooks/ +berks-cookbooks/ .kitchen/ .vagrant/ .coverage/ diff --git a/.rubocop.yml b/.rubocop.yml index 5500e6d..69447d8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,6 +13,7 @@ Encoding: Exclude: - metadata.rb - Gemfile + - berks-cookbooks/** NumericLiterals: Enabled: false diff --git a/Gemfile b/Gemfile index 7548b1d..8f795fd 100644 --- a/Gemfile +++ b/Gemfile @@ -9,3 +9,4 @@ gem 'chefspec', '~> 4.0.0' gem 'rspec', '~> 3.0.0' gem 'foodcritic', '~> 3.0.3' gem 'rubocop', '~> 0.18.1' +gem 'rake', '~> 10.0' diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..e9952df --- /dev/null +++ b/Rakefile @@ -0,0 +1,33 @@ +task default: ["test"] + +task :test => [:lint, :style, :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 :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 diff --git a/TESTING.md b/TESTING.md index c4b847d..b38785b 100644 --- a/TESTING.md +++ b/TESTING.md @@ -1,18 +1,18 @@ # Testing the Cookbook # -This cookbook uses [bundler](http://gembundler.com/) and [berkshelf](http://berkshelf.com/) to isolate dependencies. +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). -To setup the dependencies: +We have three test suites which you can run individually (there are three rake tasks): - $ bundle install --path=.bundle # install gem dependencies - $ bundle exec berks vendor .cookbooks # install cookbook dependencies and create the folder .cookbooks + $ rake lint + $ rake style + $ rake unit -To run the tests: +or altogether: - $ export COOKBOOK='openstack-orchestration' - $ bundle exec foodcritic -f any -t ~FC003 -t ~FC023 .cookbooks/$COOKBOOK - $ bundle exec rubocop .cookbooks/$COOKBOOK - $ bundle exec rspec --format documentation .cookbooks/$COOKBOOK/spec + $ rake test + +The `rake` tasks will take care of installing the needed gem dependencies and cookbooks with `berkshelf`. ## Rubocop ##