Browse Source

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: If366dff9394f416b0704bea89ae50c1c472606bf
blueprint: rakefile
tags/eol-juno
Ionuț Arțăriși 4 years ago
parent
commit
17eff9523c
5 changed files with 46 additions and 11 deletions
  1. 1
    1
      .gitignore
  2. 1
    0
      .rubocop.yml
  3. 1
    0
      Gemfile
  4. 33
    0
      Rakefile
  5. 10
    10
      TESTING.md

+ 1
- 1
.gitignore View File

@@ -1,5 +1,5 @@
1 1
 .bundle/
2
-.cookbooks/
2
+berks-cookbooks/
3 3
 .kitchen/
4 4
 .vagrant/
5 5
 .coverage/

+ 1
- 0
.rubocop.yml View File

@@ -13,6 +13,7 @@ Encoding:
13 13
   Exclude:
14 14
     - metadata.rb
15 15
     - Gemfile
16
+    - berks-cookbooks/**
16 17
 
17 18
 NumericLiterals:
18 19
   Enabled: false

+ 1
- 0
Gemfile View File

@@ -10,3 +10,4 @@ gem 'rspec', '~> 3.0.0'
10 10
 gem 'foodcritic', '~> 3.0.3'
11 11
 gem 'rubocop', '~> 0.18.1'
12 12
 gem 'fauxhai', '>= 2.1.0'
13
+gem 'rake', '~> 10.0'

+ 33
- 0
Rakefile View File

@@ -0,0 +1,33 @@
1
+task default: ["test"]
2
+
3
+task :test => [:lint, :style, :unit]
4
+
5
+task :bundler_prep do
6
+  mkdir_p '.bundle'
7
+  sh %{bundle install --path=.bundle --jobs 1 --retry 3 --verbose}
8
+end
9
+
10
+task :berks_prep => :bundler_prep do
11
+  sh %{bundle exec berks vendor}
12
+end
13
+
14
+task :lint => :bundler_prep do
15
+  sh %{bundle exec foodcritic --epic-fail any --tags ~FC003 --tags ~FC023 .}
16
+end
17
+
18
+task :style => :bundler_prep do
19
+  sh %{bundle exec rubocop}
20
+end
21
+
22
+task :unit => :berks_prep do
23
+  sh %{bundle exec rspec --format documentation}
24
+end
25
+
26
+task :clean do
27
+  rm_rf [
28
+    '.bundle',
29
+    'berks-cookbooks',
30
+    'Gemfile.lock',
31
+    'Berksfile.lock'
32
+  ]
33
+end

+ 10
- 10
TESTING.md View File

@@ -1,18 +1,18 @@
1 1
 # Testing the Cookbook #
2 2
 
3
-This cookbook uses [bundler](http://gembundler.com/) and [berkshelf](http://berkshelf.com/) to isolate dependencies.
3
+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).
4 4
 
5
-To setup the dependencies:
5
+We have three test suites which you can run individually (there are three rake tasks):
6 6
 
7
-    $ bundle install --path=.bundle # install gem dependencies
8
-    $ bundle exec berks vendor .cookbooks # install cookbook dependencies and create the folder .cookbooks
7
+    $ rake lint
8
+    $ rake style
9
+    $ rake unit
9 10
 
10
-To run the tests:
11
+or altogether:
11 12
 
12
-    $ export COOKBOOK='openstack-block-storage'
13
-    $ bundle exec foodcritic -f any -t ~FC003 -t ~FC023 .cookbooks/$COOKBOOK
14
-    $ bundle exec rubocop .cookbooks/$COOKBOOK
15
-    $ bundle exec rspec --format documentation .cookbooks/$COOKBOOK/spec
13
+    $ rake test
14
+
15
+The `rake` tasks will take care of installing the needed gem dependencies and cookbooks with `berkshelf`.
16 16
 
17 17
 ## Rubocop  ##
18 18
 
@@ -27,4 +27,4 @@ To run the tests:
27 27
 
28 28
 ## Chefspec
29 29
 
30
-[ChefSpec](http://github.com/sethvargo/chefspec/) is a unit testing framework for testing Chef cookbooks. ChefSpec makes it easy to write examples and get fast feedback on cookbook changes without the need for virtual machines or cloud servers.
30
+[ChefSpec](http://code.sethvargo.com/chefspec/) is a unit testing framework for testing Chef cookbooks. ChefSpec makes it easy to write examples and get fast feedback on cookbook changes without the need for virtual machines or cloud servers.

Loading…
Cancel
Save