From 67a294f22355b222e035e7c2a1a47fadfc949cf8 Mon Sep 17 00:00:00 2001 From: Mick Brooks Date: Thu, 27 Feb 2014 23:35:20 -0500 Subject: [PATCH] [COOK-4329] Migrate minitest PITs to latest test-kitchen + serverspec Signed-off-by: Sean OMeara --- .kitchen.yml | 3 +++ Gemfile | 4 ++-- TESTING.md | 12 ++++------ .../aliases/serverspec/aliases_spec.rb | 11 ++++----- .../client/serverspec/client_spec.rb | 5 ++-- .../default/serverspec/default_spec.rb | 24 ++++++++----------- .../sasl_auth/serverspec/sasl_auth_spec.rb | 15 ++++++------ .../server/serverspec/server_spec.rb | 5 ++-- test/shared/spec_helper.rb | 12 ++++++++++ 9 files changed, 48 insertions(+), 43 deletions(-) rename files/default/tests/minitest/aliases_test.rb => test/integration/aliases/serverspec/aliases_spec.rb (74%) rename files/default/tests/minitest/client_test.rb => test/integration/client/serverspec/client_spec.rb (76%) rename files/default/tests/minitest/default_test.rb => test/integration/default/serverspec/default_spec.rb (59%) rename files/default/tests/minitest/sasl_auth_test.rb => test/integration/sasl_auth/serverspec/sasl_auth_spec.rb (60%) rename files/default/tests/minitest/server_test.rb => test/integration/server/serverspec/server_spec.rb (75%) create mode 100644 test/shared/spec_helper.rb diff --git a/.kitchen.yml b/.kitchen.yml index ee314dc..1da2578 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -3,6 +3,9 @@ driver_plugin: vagrant driver_config: require_chef_omnibus: true +provisioner: + data_path: test/shared + platforms: - name: ubuntu-12.04 run_list: diff --git a/Gemfile b/Gemfile index 3fc386a..fe378ba 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,6 @@ gem 'foodcritic', '~> 3.0' gem 'rubocop', '~> 0.14' group :integration do - gem 'test-kitchen', '~> 1.0.0.beta.4' - gem 'kitchen-vagrant', '~> 0.11' + gem 'test-kitchen', '~> 1.1.0' + gem 'kitchen-vagrant', '~> 0.14' end diff --git a/TESTING.md b/TESTING.md index e29ff7c..2b6e4ff 100644 --- a/TESTING.md +++ b/TESTING.md @@ -1,7 +1,7 @@ -This cookbook includes support for running tests via Test Kitchen (1.0). This has some requirements. +This cookbook includes support for running tests via Test Kitchen (1.1). This has some requirements. 1. You must be using the Git repository, rather than the downloaded cookbook from the Chef Community Site. -2. You must have Vagrant 1.1 installed. +2. You must have Vagrant 1.1 or higher installed. 3. You must have a "sane" Ruby 1.9.3 environment. Once the above requirements are met, install the additional requirements: @@ -11,13 +11,9 @@ Install the berkshelf plugin for vagrant, and berkshelf to your local Ruby envir vagrant plugin install vagrant-berkshelf gem install berkshelf -Install Test Kitchen 1.0 (unreleased yet, use the alpha / prerelease version). +Install Test Kitchen and its Vagrant driver. - gem install test-kitchen --pre - -Install the Vagrant driver for Test Kitchen. - - gem install kitchen-vagrant + bundle install Once the above are installed, you should be able to run Test Kitchen: diff --git a/files/default/tests/minitest/aliases_test.rb b/test/integration/aliases/serverspec/aliases_spec.rb similarity index 74% rename from files/default/tests/minitest/aliases_test.rb rename to test/integration/aliases/serverspec/aliases_spec.rb index 626308f..88c88df 100644 --- a/files/default/tests/minitest/aliases_test.rb +++ b/test/integration/aliases/serverspec/aliases_spec.rb @@ -14,13 +14,12 @@ # limitations under the License. # -require File.expand_path('../support/helpers', __FILE__) +require_relative '../../../kitchen/data/spec_helper' describe 'postfix::aliases' do - include Helpers::Postfix - - it 'manages aliases' do - file("#{node['postfix']['conf_dir']}/aliases").must_match(/^# This file is generated by Chef for/) + context 'configures' do + describe file('/etc/aliases') do + its(:content) { should match(/^# This file is generated by Chef for/) } + end end - end diff --git a/files/default/tests/minitest/client_test.rb b/test/integration/client/serverspec/client_spec.rb similarity index 76% rename from files/default/tests/minitest/client_test.rb rename to test/integration/client/serverspec/client_spec.rb index d9c3aaa..8b95d41 100644 --- a/files/default/tests/minitest/client_test.rb +++ b/test/integration/client/serverspec/client_spec.rb @@ -14,11 +14,10 @@ # limitations under the License. # -require File.expand_path('../support/helpers', __FILE__) +require_relative '../../../kitchen/data/spec_helper' describe 'postfix::client' do - include Helpers::Postfix it 'doesnt configure postfix because solo is unsupported' do - skip 'Postfix may be set up by default on the system, but not configured by Chef because this test assumes it is run under Chef Solo' + pending 'Postfix may be set up by default on the system, but not configured by Chef because this test assumes it is run under Chef Solo' end end diff --git a/files/default/tests/minitest/default_test.rb b/test/integration/default/serverspec/default_spec.rb similarity index 59% rename from files/default/tests/minitest/default_test.rb rename to test/integration/default/serverspec/default_spec.rb index c5682d8..7b0775b 100644 --- a/files/default/tests/minitest/default_test.rb +++ b/test/integration/default/serverspec/default_spec.rb @@ -14,25 +14,21 @@ # limitations under the License. # -require File.expand_path('../support/helpers', __FILE__) +require_relative '../../../kitchen/data/spec_helper' describe 'postfix::default' do - include Helpers::Postfix - - it 'installs the postfix package' do - package('postfix').must_be_installed + describe package('postfix') do + it { should be_installed } end - it 'enables the postfix service' do - service('postfix').must_be_enabled + describe service('postfix') do + it { should be_enabled } + it { should be_running } end - it 'starts the postfix service' do - service('postfix').must_be_running + context 'configures' do + describe file('/etc/postfix/main.cf') do + its(:content) { should match /^# Generated by Chef for / } + end end - - it 'configures postfix main.cf' do - file("#{node['postfix']['conf_dir']}/main.cf").must_match(/^# Generated by Chef for /) - end - end diff --git a/files/default/tests/minitest/sasl_auth_test.rb b/test/integration/sasl_auth/serverspec/sasl_auth_spec.rb similarity index 60% rename from files/default/tests/minitest/sasl_auth_test.rb rename to test/integration/sasl_auth/serverspec/sasl_auth_spec.rb index 2888d67..51f388a 100644 --- a/files/default/tests/minitest/sasl_auth_test.rb +++ b/test/integration/sasl_auth/serverspec/sasl_auth_spec.rb @@ -13,17 +13,18 @@ # See the License for the specific language governing permissions and # limitations under the License. # -require File.expand_path('../support/helpers', __FILE__) +require_relative '../../../kitchen/data/spec_helper' describe 'postfix::sasl_auth' do - include Helpers::Postfix + let(:sasl_passwd_file) { '/etc/postfix/sasl_passwd' } - it "manages postfix sasl_passwd" do - file("#{node['potfix']['conf_dir']}/sasl_passwd").must_match(/^# This file is generated by Chef for/) + it 'manages postfix sasl_passwd' do + expect(file(sasl_passwd_file).content). + to match(/^# This file is generated by Chef for/) end - it 'configures postfix to use /etc/postfix/sasl_passwd' do - file('/etc/postfix/main.cf').must_match(/^\s*smtp_sasl_password_maps\s*=.*\/etc\/postfix\/sasl_passwd\s*$/) + it 'configures postfix to use the sasl_passwd file' do + expect(file('/etc/postfix/main.cf').content). + to match(/^\s*smtp_sasl_password_maps\s*=.*#{sasl_passwd_file}\s*$/) end - end diff --git a/files/default/tests/minitest/server_test.rb b/test/integration/server/serverspec/server_spec.rb similarity index 75% rename from files/default/tests/minitest/server_test.rb rename to test/integration/server/serverspec/server_spec.rb index 123c72c..a5c443e 100644 --- a/files/default/tests/minitest/server_test.rb +++ b/test/integration/server/serverspec/server_spec.rb @@ -13,11 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # -require File.expand_path('../support/helpers', __FILE__) +require_relative '../../../kitchen/data/spec_helper' describe 'postfix::server' do - include Helpers::Postfix it 'doesnt configure postfix because solo is unsupported' do - skip 'Postfix may be set up by default on the system, but not configured by Chef because this test assumes it is run under Chef Solo' + pending 'Postfix may be set up by default on the system, but not configured by Chef because this test assumes it is run under Chef Solo' end end diff --git a/test/shared/spec_helper.rb b/test/shared/spec_helper.rb new file mode 100644 index 0000000..43c0966 --- /dev/null +++ b/test/shared/spec_helper.rb @@ -0,0 +1,12 @@ +require 'serverspec' + +include SpecInfra::Helper::Exec +include SpecInfra::Helper::DetectOS + +RSpec.configure do |config| + config.before(:all) do + # centos-59 doesn't have /sbin in the default path, + # so we must ensure it's on serverspec's path + config.path = '/sbin' + end +end