Skip to content

Commit

Permalink
Merge pull request #63 from RoboticCheese/jdh-assorted-updates
Browse files Browse the repository at this point in the history
Add a remove test suite
  • Loading branch information
hartmantis committed Jan 25, 2016
2 parents a748b60 + ef39cf4 commit 42634fb
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 12 deletions.
10 changes: 10 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ suites:
- name: default
run_list:
- recipe[chef-dk]
- name: remove
run_list:
- recipe[chef-dk_test::remove]
attributes:
chef_dk:
global_shell_init: true
excludes:
- macosx
- windows-2012
- windows
- name: global_shell_init
run_list:
- recipe[chef-dk]
Expand Down
4 changes: 4 additions & 0 deletions Berksfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ group :test do
cookbook 'chef_dk_shell_init_test',
path: 'spec/support/cookbooks/chef_dk_shell_init_test'
end

group :integration do
cookbook 'chef-dk_test', path: 'test/fixtures/cookbooks/chef-dk_test'
end
4 changes: 2 additions & 2 deletions libraries/provider_chef_dk_debian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ def install!
end

#
# Use the normal `package` resource to remove the Chef-DK.
# Use the `dpkg_package` resource to remove the Chef-DK.
#
# (see Chef::Provider::ChefDk#remove!)
#
def remove!
package 'chefdk' do
dpkg_package 'chefdk' do
action :remove
end
end
Expand Down
4 changes: 2 additions & 2 deletions libraries/provider_chef_dk_rhel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ def install!
end

#
# Use the normal `package` resource to remove the Chef-DK.
# Use the `rpm_package` resource to remove the Chef-DK.
#
# (see Chef::Provider::ChefDk#remove!)
#
def remove!
package 'chefdk' do
rpm_package 'chefdk' do
action :remove
end
end
Expand Down
6 changes: 2 additions & 4 deletions spec/libraries/provider_chef_dk_debian_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@

describe '#remove!' do
before(:each) do
allow_any_instance_of(described_class).to receive(:package)
allow_any_instance_of(described_class).to receive(:node)
.and_return('platform' => 'ubuntu')
allow_any_instance_of(described_class).to receive(:dpkg_package)
end

it 'removes the Chef-DK package' do
p = provider
expect(p).to receive(:package).with('chefdk').and_yield
expect(p).to receive(:dpkg_package).with('chefdk').and_yield
expect(p).to receive(:action).with(:remove)
p.send(:remove!)
end
Expand Down
6 changes: 2 additions & 4 deletions spec/libraries/provider_chef_dk_rhel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,12 @@

describe '#remove!' do
before(:each) do
allow_any_instance_of(described_class).to receive(:package)
allow_any_instance_of(described_class).to receive(:node)
.and_return('platform' => 'redhat')
allow_any_instance_of(described_class).to receive(:rpm_package)
end

it 'removes the Chef-DK package' do
p = provider
expect(p).to receive(:package).with('chefdk').and_yield
expect(p).to receive(:rpm_package).with('chefdk').and_yield
expect(p).to receive(:action).with(:remove)
p.send(:remove!)
end
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/cookbooks/chef-dk_test/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Encoding: UTF-8

name 'chef-dk_test'
maintainer 'Jonathan Hartman'
maintainer_email 'j@p4nt5.com'
license 'apache2'
description 'chef-dk_test'
long_description 'chef-dk_test'
version '0.0.1'

depends 'chef-dk'

supports 'ubuntu'
supports 'debian'
supports 'redhat'
supports 'centos'
supports 'scientific'
supports 'amazon'
supports 'fedora'
supports 'mac_os_x'
supports 'windows'
7 changes: 7 additions & 0 deletions test/fixtures/cookbooks/chef-dk_test/recipes/remove.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Encoding: UTF-8

include_recipe 'chef-dk'

chef_dk 'default' do
action :remove
end
22 changes: 22 additions & 0 deletions test/integration/remove/serverspec/localhost/environment_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Encoding: UTF-8

require_relative '../spec_helper'

describe 'chef-dk::remove::environment' do
shared_examples_for 'file without chef shell-init' do
it 'does not contain the chef shell-init command' do
matcher = /^eval "\$\(chef shell-init bash\)"$/
expect(subject.content).to_not match(matcher)
end
end

describe file('/etc/bashrc'),
if: %w(darwin redhat fedora).include?(os[:family]) do
it_behaves_like 'file without chef shell-init'
end

describe file('/etc/bash.bashrc'),
if: %w(ubuntu debian).include?(os[:family]) do
it_behaves_like 'file without chef shell-init'
end
end
25 changes: 25 additions & 0 deletions test/integration/remove/serverspec/localhost/package_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Encoding: UTF-8

require_relative '../spec_helper'

describe 'chef-dk::remove::package' do
describe package('com.getchef.pkg.chefdk'), if: os[:family] == 'darwin' do
it 'is not installed' do
expect(subject).to_not be_installed.by(:pkgutil)
end
end

# On Windows, the package name changes to reflect each ChefDK version
describe package('Chef Development Kit v*'), if: os[:family] == 'windows' do
it 'is not installed' do
expect(subject).to_not be_installed
end
end

describe package('chefdk'),
if: %w(ubuntu debian redhat fedora).include?(os[:family]) do
it 'is not installed' do
expect(subject).to_not be_installed
end
end
end
10 changes: 10 additions & 0 deletions test/integration/remove/serverspec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Encoding: UTF-8

require 'serverspec'

if RUBY_PLATFORM =~ /mswin|mingw32|windows/
set :os, family: 'windows'
set :backend, :cmd
else
set :backend, :exec
end

0 comments on commit 42634fb

Please sign in to comment.