From f3d6b771b4a6317f598543bbda10df774ad2a1ce Mon Sep 17 00:00:00 2001 From: sean Date: Mon, 10 Jun 2013 08:06:03 -0700 Subject: [PATCH] Use strainer to isolate and test individual cookbooks Included: - Add strainer gem - Update test-related gems - Add Strainer file - Remove run_tests.bash - Update .gitignore - Update README file - Update specs to use require_relative Partial fix for bug 1188345 Change-Id: I6cb9e535212346cccb45f8c41c647b8daa8a4c7d --- .gitignore | 3 +-- Gemfile | 9 +++++---- Gemfile.lock | 11 ++++++---- README.md | 13 ++++++++---- Strainerfile | 5 +++++ run_tests.bash | 20 ------------------- .../ceilometer-agent-central-opensuse_spec.rb | 2 +- spec/ceilometer-agent-central_spec.rb | 2 +- spec/ceilometer-agent-compute_spec.rb | 2 +- spec/ceilometer-common-opensuse_spec.rb | 2 +- spec/ceilometer-common_spec.rb | 2 +- spec/libvirt-opensuse_spec.rb | 2 +- 12 files changed, 33 insertions(+), 40 deletions(-) create mode 100644 Strainerfile delete mode 100755 run_tests.bash diff --git a/.gitignore b/.gitignore index 1142e2d4..c6ba7b77 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -.bundle -.cookbooks/ +.bundle/ Berksfile.lock diff --git a/Gemfile b/Gemfile index 2b5c0a23..7de4657f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,9 @@ source "https://rubygems.org" gem "chef", "~> 11.4.4" -gem "json", "= 1.7.7" # chef 11 dependency -gem "berkshelf", "~> 1.4.0" +gem "json", "<= 1.7.7" # chef 11 dependency +gem "berkshelf", "~> 1.4.5" gem "chefspec", "~> 1.2.0" -gem "foodcritic", "~> 2.1.0" -gem "tailor", "~> 1.2.1" +gem "foodcritic" +gem "strainer" +gem "tailor" diff --git a/Gemfile.lock b/Gemfile.lock index d37732b4..08e2917e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -165,6 +165,8 @@ GEM wasabi (~> 1.0) solve (0.4.4) json + strainer (2.1.0) + berkshelf (~> 1.3) systemu (2.5.2) tailor (1.2.1) log_switch (>= 0.3.0) @@ -196,9 +198,10 @@ PLATFORMS ruby DEPENDENCIES - berkshelf (~> 1.4.0) + berkshelf (~> 1.4.5) chef (~> 11.4.4) chefspec (~> 1.2.0) - foodcritic (~> 2.1.0) - json (= 1.7.7) - tailor (~> 1.2.1) + foodcritic + json (<= 1.7.7) + strainer + tailor diff --git a/README.md b/README.md index d4161682..104a3983 100644 --- a/README.md +++ b/README.md @@ -212,11 +212,15 @@ OSAPI Compute Extentions Testing ===== -This cookbook is using [ChefSpec](https://github.com/acrmp/chefspec) for -testing. Run the following before commiting. It will run your tests, -and check for lint errors. +This cookbook uses [bundler](http://gembundler.com/), [berkshelf](http://berkshelf.com/), and [strainer](https://github.com/customink/strainer) to isolate dependencies and run tests. - $ ./run_tests.bash +Tests are defined in Strainerfile. + +To run tests: + + $ bundle install # install gem dependencies + $ bundle exec berks install # install cookbook dependencies + $ bundle exec strainer test # run tests License and Author ================== @@ -234,6 +238,7 @@ License and Author | **Author** | Jay Pipes () | | **Author** | John Dewey () | | **Author** | Craig Tracey () | +| **Author** | Sean Gallagher () | | | | | **Copyright** | Copyright (c) 2012-2013, Rackspace US, Inc. | | **Copyright** | Copyright (c) 2012-2013, Opscode, Inc. | diff --git a/Strainerfile b/Strainerfile new file mode 100644 index 00000000..7e292b43 --- /dev/null +++ b/Strainerfile @@ -0,0 +1,5 @@ +# Strainerfile +tailor: bundle exec tailor +knife test: bundle exec knife cookbook test $COOKBOOK +foodcritic: bundle exec foodcritic -f any -t ~FC003 -t ~FC023 $SANDBOX/$COOKBOOK +chefspec: bundle exec rspec $SANDBOX/$COOKBOOK/spec diff --git a/run_tests.bash b/run_tests.bash deleted file mode 100755 index 870fa560..00000000 --- a/run_tests.bash +++ /dev/null @@ -1,20 +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} - -bundle install --path=${BUNDLE_PATH} -bundle exec berks install --path=${BERKSHELF_PATH} -bundle exec foodcritic -f any -t ~FC003 -t ~FC023 ${BERKSHELF_PATH}/${COOKBOOK} -bundle exec tailor -bundle exec rspec ${BERKSHELF_PATH}/${COOKBOOK} diff --git a/spec/ceilometer-agent-central-opensuse_spec.rb b/spec/ceilometer-agent-central-opensuse_spec.rb index ed156a42..c3d4cad1 100644 --- a/spec/ceilometer-agent-central-opensuse_spec.rb +++ b/spec/ceilometer-agent-central-opensuse_spec.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require_relative "spec_helper" describe "openstack-compute::ceilometer-agent-central" do describe "opensuse" do diff --git a/spec/ceilometer-agent-central_spec.rb b/spec/ceilometer-agent-central_spec.rb index 93cca455..69bc3594 100644 --- a/spec/ceilometer-agent-central_spec.rb +++ b/spec/ceilometer-agent-central_spec.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require_relative "spec_helper" describe "openstack-compute::ceilometer-agent-central" do describe "ubuntu" do diff --git a/spec/ceilometer-agent-compute_spec.rb b/spec/ceilometer-agent-compute_spec.rb index 7d9922b1..f42074e9 100644 --- a/spec/ceilometer-agent-compute_spec.rb +++ b/spec/ceilometer-agent-compute_spec.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require_relative "spec_helper" describe "openstack-compute::ceilometer-agent-compute" do describe "ubuntu" do diff --git a/spec/ceilometer-common-opensuse_spec.rb b/spec/ceilometer-common-opensuse_spec.rb index edabfa1b..3c8ab920 100644 --- a/spec/ceilometer-common-opensuse_spec.rb +++ b/spec/ceilometer-common-opensuse_spec.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require_relative "spec_helper" describe "openstack-compute::ceilometer-common" do describe "opensuse" do diff --git a/spec/ceilometer-common_spec.rb b/spec/ceilometer-common_spec.rb index 2e384585..db6fb716 100644 --- a/spec/ceilometer-common_spec.rb +++ b/spec/ceilometer-common_spec.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require_relative "spec_helper" describe "openstack-compute::ceilometer-common" do describe "ubuntu" do diff --git a/spec/libvirt-opensuse_spec.rb b/spec/libvirt-opensuse_spec.rb index d27ea9dd..eaeb25c5 100644 --- a/spec/libvirt-opensuse_spec.rb +++ b/spec/libvirt-opensuse_spec.rb @@ -1,4 +1,4 @@ -require "spec_helper" +require_relative "spec_helper" describe "openstack-compute::libvirt" do before do