Skip to content

Commit

Permalink
Add integration tests for repo installs
Browse files Browse the repository at this point in the history
  • Loading branch information
hartmantis committed Jul 25, 2016
1 parent 4591778 commit d9b75d4
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 3 deletions.
14 changes: 13 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ suites:
- name: remove
run_list:
- recipe[chef-dk_test::remove]
- name: install_from_specific_url
- name: repo
run_list:
- recipe[chef-dk_test]
attributes:
chef_dk:
source: repo
- name: repo_remove
run_list:
- recipe[chef-dk_test::remove]
attributes:
chef_dk:
source: repo
- name: custom
run_list:
- recipe[chef-dk_test]
attributes:
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/cookbooks/chef-dk_test/recipes/remove.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
include_recipe 'chef-dk'

chef_dk 'default' do
source node['chef_dk']['source'] unless node['chef_dk']['source'].nil?
action :remove
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require_relative '../spec_helper'

describe 'chef-dk::install_from_specific_url::environment' do
describe 'chef-dk::custom::environment' do
shared_examples_for 'file with chef shell-init' do
it 'contains the chef shell-init command' do
matcher = /^eval "\$\(chef shell-init bash\)"$/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require_relative '../spec_helper'

describe 'chef-dk::install_from_specific_url::package' do
describe 'chef-dk::custom::package' do
describe package('chefdk') do
it 'is installed with the right version' do
expect(subject).to be_installed.with_version('0.14.25-1')
Expand Down
38 changes: 38 additions & 0 deletions test/integration/repo/serverspec/localhost/environment_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# encoding: utf-8
# frozen_string_literal: true

require_relative '../spec_helper'

describe 'chef-dk::repo::environment' do
shared_examples_for 'file with chef shell-init' do
it 'contains the chef shell-init command' do
matcher = /^eval "\$\(chef shell-init bash\)"$/
expect(subject.content).to match(matcher)
end
end

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

describe file('/etc/bash.bashrc'),
if: %w(ubuntu debian).include?(os[:family]) do
it_behaves_like 'file with chef shell-init'
end

describe command('/opt/chefdk/embedded/bin/gem list cabin'),
if: os[:family] != 'windows' do
it 'shows the requested gem is installed' do
expect(subject.stdout).to match(/^cabin \(/)
end
end

describe file(
'~/AppData/Local/chefdk/gem/ruby/2.1.0/bin/rubygems-cabin-test'
), if: os[:family] == 'windows' do
it 'shows the requested gem is installed' do
expect(subject).to exist
end
end
end
52 changes: 52 additions & 0 deletions test/integration/repo/serverspec/localhost/package_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# encoding: utf-8
# frozen_string_literal: true

require_relative '../spec_helper'

describe 'chef-dk::repo::package' do
describe command('brew list chefdk'), if: os[:family] == 'darwin' do
it 'indicates Chef-DK is installed' do
expect(subject.exit_status).to eq(0)
end
end

describe command('chocolatey list chefdk'), if: os[:family] == 'windows' do
it 'indicates Chef-DK is installed' do
expect(subject.exit_status).to eq(0)
end
end

describe file('/etc/apt/sources.list.d/chef-stable.list'),
if: %w(ubuntu debian).include?(os[:family]) do
it 'exists' do
expect(subject).to be_file
end
end

describe file('/etc/yum.repos.d/chef-stable.repo'),
if: %w(redhat fedora).include?(os[:family]) do
it 'exists' do
expect(subject).to be_file
end
end

describe package('com.getchef.pkg.chefdk'), if: os[:family] == 'darwin' do
it 'is installed' do
expect(subject).to 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 installed' do
expect(subject).to be_installed
end
end

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

require 'serverspec'

if RUBY_PLATFORM =~ /mswin|mingw32|windows/
set :os, family: 'windows'
set :backend, :cmd
else
set :backend, :exec
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# encoding: utf-8
# frozen_string_literal: true

require_relative '../spec_helper'

describe 'chef-dk::repo_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

describe file('~/.chefdk/gem/ruby/2.1.0/bin/rubygems-cabin-test'),
if: os[:family] != 'windows' do
it 'does not exist' do
expect(subject).to_not exist
end
end

describe file(
'~/AppData/Local/chefdk/gem/ruby/2.1.0/bin/rubygems-cabin-test'
), if: os[:family] == 'windows' do
it 'does not exist' do
expect(subject).to_not exist
end
end
end
38 changes: 38 additions & 0 deletions test/integration/repo_remove/serverspec/localhost/package_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# encoding: utf-8
# frozen_string_literal: true

require_relative '../spec_helper'

describe 'chef-dk::repo_remove::package' do
describe command('brew list chefdk'), if: os[:family] == 'darwin' do
it 'indicates Chef-DK is not installed' do
expect(subject.exit_status).to eq(1)
end
end

describe command('chocolatey list chefdk'), if: os[:family] == 'windows' do
it 'indicates Chef-DK is not installed' do
expect(subject.exit_status).to eq(1)
end
end

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
11 changes: 11 additions & 0 deletions test/integration/repo_remove/serverspec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# encoding: utf-8
# frozen_string_literal: true

require 'serverspec'

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

0 comments on commit d9b75d4

Please sign in to comment.