Skip to content

Commit

Permalink
refactor rspec tests to use rspec-puppet-facts
Browse files Browse the repository at this point in the history
  • Loading branch information
dannygoulder committed Oct 9, 2016
1 parent a10f9c4 commit 4159db4
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 256 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ group :development, :test do
gem 'puppet-lint', :require => false
gem 'pry', :require => false
gem 'simplecov', :require => false
gem 'rspec-puppet-facts', :require => false
end

# pin old versions for ruby 1.8.7
Expand Down
335 changes: 79 additions & 256 deletions spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
@@ -1,276 +1,99 @@
require 'spec_helper'

describe 'python', :type => :class do
context "on Debian OS" do
let :facts do
{
:id => 'root',
:kernel => 'Linux',
:lsbdistcodename => 'squeeze',
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
:concat_basedir => '/dne',
}
end

it { is_expected.to contain_class("python::install") }
# Base debian packages.
it { is_expected.to contain_package("python") }
it { is_expected.to contain_package("python-dev") }
it { is_expected.to contain_package("pip") }
# Basic python packages (from pip)
it { is_expected.to contain_package("virtualenv")}

describe "with python::dev" do
context "true" do
let (:params) {{ :dev => 'present' }}
it { is_expected.to contain_package("python-dev").with_ensure('present') }
end
context "empty/default" do
it { is_expected.to contain_package("python-dev").with_ensure('absent') }
end
end

describe "with manage_gunicorn" do
context "true" do
let (:params) {{ :manage_gunicorn => true }}
it { is_expected.to contain_package("gunicorn") }
end
context "empty args" do
#let (:params) {{ :manage_gunicorn => '' }}
it { is_expected.to contain_package("gunicorn") }
end
context "false" do
let (:params) {{ :manage_gunicorn => false }}
it {is_expected.not_to contain_package("gunicorn")}
end
end

describe "with python::provider" do
context "pip" do
let (:params) {{ :provider => 'pip' }}
it { is_expected.to contain_package("virtualenv").with(
'provider' => 'pip'
)}
it { is_expected.to contain_package("pip").with(
'provider' => 'pip'
)}
end

# python::provider
context "default" do
let (:params) {{ :provider => '' }}
it { is_expected.to contain_package("virtualenv")}
it { is_expected.to contain_package("pip")}

describe "with python::virtualenv" do
context "true" do
let (:params) {{ :provider => '', :virtualenv => true }}
it { is_expected.to contain_package("virtualenv").with_ensure('present') }
end
on_supported_os.each do |os, facts|
context "on #{os}" do
let :facts do
facts
end

it { is_expected.to contain_class("python::install") }
# Base debian packages.
it { is_expected.to contain_package("python") }
case facts[:osfamily]
when 'Debian'
it { is_expected.to contain_package("python-dev").with_alias("python-dev") }
when 'RedHat', 'Suse'
it { is_expected.to contain_package("python-dev").with_name("python-devel") }
it { is_expected.to contain_package("python-dev").with_alias("python-devel") }
end

it { is_expected.to contain_package("pip") }
# Basic python packages (from pip)
it { is_expected.to contain_package("virtualenv")}

describe "with python::dev" do
context "true" do
let (:params) {{ :dev => 'present' }}
it { is_expected.to contain_package("python-dev").with_ensure('present') }
end

describe "without python::virtualenv" do
context "default/empty" do
let (:params) {{ :provider => '' }}
it { is_expected.to contain_package("virtualenv").with_ensure('absent') }
end
context "empty/default" do
it { is_expected.to contain_package("python-dev").with_ensure('absent') }
end
end
end

describe "with python::dev" do
context "true" do
let (:params) {{ :dev => 'present' }}
it { is_expected.to contain_package("python-dev").with_ensure('present') }
end
context "default/empty" do
it { is_expected.to contain_package("python-dev").with_ensure('absent') }
end
end
end

context "on a Redhat 5 OS" do
let :facts do
{
:id => 'root',
:kernel => 'Linux',
:osfamily => 'RedHat',
:operatingsystem => 'RedHat',
:operatingsystemrelease => '5',
:concat_basedir => '/dne',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
it { is_expected.to contain_class("python::install") }
# Base debian packages.
it { is_expected.to contain_package("python") }
it { is_expected.to contain_package("python-dev").with_name("python-devel") }
it { is_expected.to contain_package("python-dev").with_alias("python-devel") }
it { is_expected.to contain_package("pip") }
# Basic python packages (from pip)
it { is_expected.to contain_package("virtualenv")}

describe "with python::dev" do
context "true" do
let (:params) {{ :dev => 'present' }}
it { is_expected.to contain_package("python-dev").with_ensure('present') }
end
context "empty/default" do
it { is_expected.to contain_package("python-dev").with_ensure('absent') }
end
end

describe "with manage_gunicorn" do
context "true" do
let (:params) {{ :manage_gunicorn => true }}
it { is_expected.to contain_package("gunicorn") }
end
context "empty args" do
#let (:params) {{ :manage_gunicorn => '' }}
it { is_expected.to contain_package("gunicorn") }
end
context "false" do
let (:params) {{ :manage_gunicorn => false }}
it {is_expected.not_to contain_package("gunicorn")}
end
end

describe "with python::provider" do
context "pip" do
let (:params) {{ :provider => 'pip' }}

it { is_expected.to contain_package("virtualenv").with(
'provider' => 'pip'
)}
it { is_expected.to contain_package("pip").with(
'provider' => 'pip'
)}
end

# python::provider
context "default" do
let (:params) {{ :provider => '' }}
it { is_expected.to contain_package("virtualenv")}
it { is_expected.to contain_package("pip")}

describe "with python::virtualenv" do
context "true" do
let (:params) {{ :provider => '', :virtualenv => 'present' }}
it { is_expected.to contain_package("virtualenv").with_ensure('present') }
end
describe "with manage_gunicorn" do
context "true" do
let (:params) {{ :manage_gunicorn => true }}
it { is_expected.to contain_package("gunicorn") }
end

describe "with python::virtualenv" do
context "default/empty" do
let (:params) {{ :provider => '' }}
it { is_expected.to contain_package("virtualenv").with_ensure('absent') }
end
context "empty args" do
#let (:params) {{ :manage_gunicorn => '' }}
it { is_expected.to contain_package("gunicorn") }
end
context "false" do
let (:params) {{ :manage_gunicorn => false }}
it {is_expected.not_to contain_package("gunicorn")}
end
end
end

describe "with python::dev" do
context "true" do
let (:params) {{ :dev => 'present' }}
it { is_expected.to contain_package("python-dev").with_ensure('present') }
end
context "default/empty" do
it { is_expected.to contain_package("python-dev").with_ensure('absent') }
end
end
end

context "on a SLES 11 SP3" do
let :facts do
{
:id => 'root',
:kernel => 'Linux',
:lsbdistcodename => nil,
:osfamily => 'Suse',
:operatingsystem => 'SLES',
:operatingsystemrelease => '11.3',
:concat_basedir => '/dne',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
it { is_expected.to contain_class("python::install") }
# Base Suse packages.
it { is_expected.to contain_package("python") }
it { is_expected.to contain_package("python-dev").with_name("python-devel") }
it { is_expected.to contain_package("pip") }
# Basic python packages (from pip)
it { is_expected.to contain_package("virtualenv")}

describe "with python::dev" do
context "true" do
let (:params) {{ :dev => 'present' }}
it { is_expected.to contain_package("python-dev").with_ensure('present') }
end
context "empty/default" do
it { is_expected.to contain_package("python-dev").with_ensure('absent') }
end
end

describe "with manage_gunicorn" do
context "true" do
let (:params) {{ :manage_gunicorn => true }}
it { is_expected.to contain_package("gunicorn") }
end
context "empty args" do
#let (:params) {{ :manage_gunicorn => '' }}
it { is_expected.to contain_package("gunicorn") }
end
context "false" do
let (:params) {{ :manage_gunicorn => false }}
it {is_expected.not_to contain_package("gunicorn")}
end
end

describe "with python::provider" do
context "pip" do
let (:params) {{ :provider => 'pip' }}

it { is_expected.to contain_package("virtualenv").with(
'provider' => 'pip'
)}
it { is_expected.to contain_package("pip").with(
'provider' => 'pip'
)}
end

# python::provider
context "default" do
let (:params) {{ :provider => '' }}
it { is_expected.to contain_package("virtualenv")}
it { is_expected.to contain_package("pip")}
describe "with python::provider" do
context "pip" do
let (:params) {{ :provider => 'pip' }}
it { is_expected.to contain_package("virtualenv").with(
'provider' => 'pip'
)}
it { is_expected.to contain_package("pip").with(
'provider' => 'pip'
)}
end

describe "with python::virtualenv" do
context "true" do
let (:params) {{ :provider => '', :virtualenv => 'present' }}
it { is_expected.to contain_package("virtualenv").with_ensure('present') }
# python::provider
context "default" do
let (:params) {{ :provider => '' }}
it { is_expected.to contain_package("virtualenv")}
it { is_expected.to contain_package("pip")}

describe "with python::virtualenv" do
context "true" do
case facts[:osfamily]
when 'Debian'
let (:params) {{ :provider => '', :virtualenv => true }}
when 'RedHat', 'Suse'
let (:params) {{ :provider => '', :virtualenv => 'present' }}
end
it { is_expected.to contain_package("virtualenv").with_ensure('present') }
end
end
end

describe "with python::virtualenv" do
context "default/empty" do
let (:params) {{ :provider => '' }}
it { is_expected.to contain_package("virtualenv").with_ensure('absent') }
case facts[:osfamily]
when 'Debian'
describe "without python::virtualenv" do
context "default/empty" do
let (:params) {{ :provider => '' }}
it { is_expected.to contain_package("virtualenv").with_ensure('absent') }
end
end
when 'RedHat', 'Suse'
describe "with python::virtualenv" do
context "default/empty" do
let (:params) {{ :provider => '' }}
it { is_expected.to contain_package("virtualenv").with_ensure('absent') }
end
end
end
end
end
end

describe "with python::dev" do
context "true" do
let (:params) {{ :dev => 'present' }}
it { is_expected.to contain_package("python-dev").with_ensure('present') }
end
context "default/empty" do
it { is_expected.to contain_package("python-dev").with_ensure('absent') }
end
end
end
end
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
include RspecPuppetFacts
add_custom_fact :id, 'root'
add_custom_fact :kernel, 'Linux'
add_custom_fact :concat_basedir, '/dne'
add_custom_fact :path, '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
add_custom_fact :lsbdistcodename, 'squeeze', :confine => 'debian-6-x86_64'
add_custom_fact :lsbdistcodename, 'nil', :confine => 'sles-11.3-x86_64'

0 comments on commit 4159db4

Please sign in to comment.