Update Testing.md to factor out Strainer

* remove refs to Strainer
* add steps for testing
* remove knife test as it's not used in gates anymore
* remove test bash script

Change-Id: If12153cff01ab4fad3b3a014c3be95437a2f9dfc
Partial-Bug: #1350470
This commit is contained in:
Mark Vanderwiel 2014-08-18 15:43:45 -05:00
parent 0c2ecb2295
commit b8eb94faf1
2 changed files with 12 additions and 47 deletions

View File

@ -1,41 +1,29 @@
# 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.
Tests are defined in [Strainerfile](Strainerfile), which in turn calls rubocop, knife, foodcritic and chefspec.
To run all of the tests with Strainer:
$ bundle exec strainer test -s Strainerfile
Or you may run the tests individually:
To setup the dependencies:
$ bundle install --path=.bundle # install gem dependencies
$ bundle exec berks vendor .cookbooks # install cookbook dependencies and create folder .cookbooks
$ bundle exec strainer test -s Strainerfile # run tests
$ bundle exec berks vendor .cookbooks # install cookbook dependencies and create the folder .cookbooks
To run the tests:
$ export COOKBOOK='openstack-object-storage'
$ bundle exec foodcritic -f any -t ~FC003 -t ~FC023 .cookbooks/$COOKBOOK
$ bundle exec rubocop .cookbooks/$COOKBOOK
$ bundle exec rspec --format documentation .cookbooks/$COOKBOOK/spec
## Rubocop ##
[Rubocop](https://github.com/bbatsov/rubocop) is a static Ruby code analyzer, based on the community [Ruby style guide](https://github.com/bbatsov/ruby-style-guide). We are attempting to adhere to this where applicable, slowly cleaning up the cookbooks until we can turn on Rubocop for gating the commits.
### Attribute Rules ###
Since there are slight style differences between the coding of attributes, recipes and metadata files there are specific `.rubocop.yml` files for each of:
[Gemfile and metadata.rb](.rubocop.yml)
[attributes/*.rb](attributes/.rubocop.yml)
[recipes/.rubocop.yml](recipes/.rubocop.yml)
[spec/.rubocop.yml](spec/.rubocop.yml)
## Knife ##
[knife cookbook test](http://docs.opscode.com/chef/knife.html#test) is used to check the cookbook's Ruby and ERB files for basic syntax errors.
## Foodcritic ##
[Foodcritic](http://acrmp.github.io/foodcritic/) is a lint tool for Chef cookbooks. We ignore the following rules:
[FC003](http://acrmp.github.io/foodcritic/#FC003) these cookbooks are not intended for Chef Solo.
* [FC003](http://acrmp.github.io/foodcritic/#FC003) These cookbooks are not intended for Chef Solo.
* [FC023](http://acrmp.github.io/foodcritic/#FC023) Prefer conditional attributes.
## Chefspec

View File

@ -1,23 +0,0 @@
#!/usr/bin/env bash
# A script to run tests locally before committing.
set -e
COOKBOOK=$(awk '/^name/ {print $NF}' metadata.rb |tr -d \"\')
if [ -z $COOKBOOK ]; then
echo "Cookbook name not defined in metadata.rb"
    exit 1
fi
BUNDLE_PATH=${BUNDLE_PATH:-.bundle}
BERKSHELF_PATH=${BERKSHELF_PATH:-.cookbooks}
echo "Using bundle path: $BUNDLE_PATH"
echo "Using berkshelf path: $BERKSHELF_PATH"
bundle install --path=${BUNDLE_PATH}
bundle exec berks install --path=${BERKSHELF_PATH}
bundle exec rspec ${BERKSHELF_PATH}/${COOKBOOK}
bundle exec foodcritic -f any -t ~FC003 -t ~FC023 ${BERKSHELF_PATH}/${COOKBOOK}