Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rspec-puppet 1.0.0 #192

Merged
merged 10 commits into from
Dec 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ source 'https://rubygems.org'

group :rake do
gem 'puppet', '>=3.0.1'
gem 'rspec-puppet', '>=0.1.3'
gem 'rspec-puppet', '>=1.0.1'
gem 'rake', '>=0.9.2.2'
gem 'puppet-lint', '>=0.1.12'
gem 'puppetlabs_spec_helper'
gem 'puppet-blacksmith'
gem 'librarian-puppet-maestrodev'
gem 'rspec-system-puppet', :require => false
gem 'serverspec', '~> 0.11.0', :require => false
gem 'rspec-system-serverspec', :require => false
end
27 changes: 14 additions & 13 deletions spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,27 @@
{
:osfamily => facts[:osfamily],
:operatingsystem => facts[:operatingsystem],
:kernel => 'linux',
}
end

it { should include_class("nginx::params") }
it { should contain_class("nginx::params") }

it { should contain_file("/etc/nginx").with(
it { should contain_file("/etc/nginx").only_with(
:path => "/etc/nginx",
:ensure => 'directory',
:owner => 'root',
:group => 'root',
:mode => '0644'
)}
it { should contain_file("/etc/nginx/conf.d").with(
it { should contain_file("/etc/nginx/conf.d").only_with(
:path => '/etc/nginx/conf.d',
:ensure => 'directory',
:owner => 'root',
:group => 'root',
:mode => '0644'
)}
it { should contain_file("/etc/nginx/conf.mail.d").with(
it { should contain_file("/etc/nginx/conf.mail.d").only_with(
:path => '/etc/nginx/conf.mail.d',
:ensure => 'directory',
:owner => 'root',
:group => 'root',
Expand Down Expand Up @@ -104,7 +106,6 @@
{
:osfamily => facts[:osfamily],
:operatingsystem => facts[:operatingsystem],
:kernel => 'linux',
}
end
it { should contain_file("/var/nginx/client_body_temp").with(:owner => 'www-data')}
Expand Down Expand Up @@ -134,7 +135,6 @@
{
:osfamily => facts[:osfamily],
:operatingsystem => facts[:operatingsystem],
:kernel => 'linux',
}
end
it { should contain_file("/var/nginx/client_body_temp").with(:owner => 'nginx')}
Expand All @@ -150,7 +150,6 @@
{
:osfamily => 'debian',
:operatingsystem => 'debian',
:kernel => 'linux',
}
end

Expand Down Expand Up @@ -196,7 +195,7 @@
:title => 'should not set proxy_cache_path',
:attr => 'proxy_cache_path',
:value => false,
:notmatch => ' proxy_cache_path /path/to/proxy.cache levels=1 keys_zone=d2:100m max_size=500m inactive=20m;',
:notmatch => / proxy_cache_path \/path\/to\/proxy\.cache levels=1 keys_zone=d2:100m max_size=500m inactive=20m;/,
},
{
:title => 'should contain ordered appended directives',
Expand All @@ -215,8 +214,9 @@
it { should contain_file("/etc/nginx/nginx.conf").with_mode('0644') }
it param[:title] do
verify_contents(subject, "/etc/nginx/nginx.conf", Array(param[:match]))
lines = subject.resource('file', "/etc/nginx/nginx.conf").send(:parameters)[:content].split("\n")
(Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty
Array(param[:notmatch]).each do |item|
should contain_file("/etc/nginx/nginx.conf").without_content(item)
end
end
end
end
Expand Down Expand Up @@ -264,8 +264,9 @@
it { should contain_file("/etc/nginx/conf.d/proxy.conf").with_mode('0644') }
it param[:title] do
verify_contents(subject, "/etc/nginx/conf.d/proxy.conf", Array(param[:match]))
lines = subject.resource('file', "/etc/nginx/conf.d/proxy.conf").send(:parameters)[:content].split("\n")
(Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty
Array(param[:notmatch]).each do |item|
should contain_file("/etc/nginx/conf.d/proxy.conf").without_content(item)
end
end
end
end
Expand Down
84 changes: 38 additions & 46 deletions spec/classes/nginx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,53 @@
}
end

context "on a Debian OS" do
let :facts do
{
:kernel => 'linux',
:operatingsystem => 'Debian',
:osfamily => 'Debian',
:lsbdistcodename => 'precise',
:concat_basedir => '/var/lib/puppet/concat',
}
end

it { should contain_nginx__package }
it { should contain_nginx__config }
it { should contain_nginx__service }
it { should include_class("nginx::params") }
shared_examples "a Linux OS" do
it { should compile.with_all_deps }
it { should contain_class('nginx') }
it { should contain_anchor('nginx::begin') }
it { should contain_nginx__package.that_requires('Anchor[nginx::begin]') }
it { should contain_nginx__config.that_requires('Class[nginx::package]') }
it { should contain_nginx__service.that_subscribes_to('Anchor[nginx::begin]') }
it { should contain_nginx__service.that_subscribes_to('Class[nginx::package]') }
it { should contain_nginx__service.that_subscribes_to('Class[nginx::config]') }
it { should contain_anchor('nginx::end').that_requires('Class[nginx::service]') }
it { should contain_class("nginx::params") }
it { should contain_nginx__resource__upstream("upstream1") }
it { should contain_nginx__resource__vhost("test2.local") }
it { should contain_nginx__resource__location("test2.local") }
end

context "on a RedHat OS" do
let :facts do
{
:kernel => 'linux',
:operatingsystem => 'RedHat',
:osfamily => 'RedHat',
:concat_basedir => '/var/lib/puppet/concat',
}
context "Debian OS" do
it_behaves_like "a Linux OS" do
let :facts do
{
:operatingsystem => 'Debian',
:osfamily => 'Debian',
:lsbdistcodename => 'precise',
}
end
end

it { should contain_nginx__package }
it { should contain_nginx__config }
it { should contain_nginx__service }
it { should include_class("nginx::params") }
it { should contain_nginx__resource__upstream("upstream1") }
it { should contain_nginx__resource__vhost("test2.local") }
it { should contain_nginx__resource__location("test2.local") }
end

context "on a Suse OS" do
let :facts do
{
:kernel => 'linux',
:operatingsystem => 'SuSE',
:osfamily => 'Suse',
:concat_basedir => '/var/lib/puppet/concat',
}
context "RedHat OS" do
it_behaves_like "a Linux OS" do
let :facts do
{
:operatingsystem => 'RedHat',
:osfamily => 'RedHat',
}
end
end
end

it { should contain_nginx__package }
it { should contain_nginx__config }
it { should contain_nginx__service }
it { should include_class("nginx::params") }
it { should contain_nginx__resource__upstream("upstream1") }
it { should contain_nginx__resource__vhost("test2.local") }
it { should contain_nginx__resource__location("test2.local") }
context "Suse OS" do
it_behaves_like "a Linux OS" do
let :facts do
{
:operatingsystem => 'SuSE',
:osfamily => 'Suse',
}
end
end
end
end
10 changes: 9 additions & 1 deletion spec/classes/package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
'gpgkey' => 'http://nginx.org/keys/nginx_signing.key'
)}
it { should contain_file('/etc/yum.repos.d/nginx-release.repo') }
it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::redhat]') }
it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::redhat]') }
end

context "manage_repo => false" do
Expand All @@ -35,7 +37,7 @@
end

describe 'installs the requested package version' do
let(:facts) {{ :kernel => 'linux', :operatingsystem => 'redhat', :osfamily => 'redhat' }}
let(:facts) {{ :operatingsystem => 'redhat', :osfamily => 'redhat' }}
let(:params) {{ :package_ensure => '3.0.0' }}

it 'installs 3.0.0 exactly' do
Expand All @@ -58,6 +60,8 @@
'key' => '7BD9BF62',
'key_source' => 'http://nginx.org/keys/nginx_signing.key'
)}
it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::debian]') }
it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::debian]') }
end

context "package_source => 'passenger'" do
Expand Down Expand Up @@ -104,6 +108,8 @@
].each do |package|
it { should contain_package("#{package}") }
end
it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::suse]') }
it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::suse]') }
end


Expand Down Expand Up @@ -137,6 +143,8 @@
'gpgkey' => 'http://nginx.org/keys/nginx_signing.key'
)}
it { should contain_file('/etc/yum.repos.d/nginx-release.repo') }
it { should contain_anchor('nginx::package::begin').that_comes_before('Class[nginx::package::redhat]') }
it { should contain_anchor('nginx::package::end').that_requires('Class[nginx::package::redhat]') }
end

context 'fedora' do
Expand Down
9 changes: 2 additions & 7 deletions spec/classes/params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
let :facts do {
:osfamily => 'debian',
:operatingsystem => 'debian',
:kernel => 'Linux',
} end

it { should contain_nginx__params }
it { should have_class_count(1) } #only nginx::params itself
it { should have_resource_count(0) } #params class should never declare resources

# There are 4 resources in this class currently
# there should not be any more resources because it is a params class
# The resources are class[nginx::params], class[main], class[settings], stage[main]
it "Should not contain any resources" do
subject.resources.size.should == 4
end
end
end
1 change: 0 additions & 1 deletion spec/classes/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
let :facts do {
:osfamily => 'Debian',
:operatingsystem => 'debian',
:kernel => 'Linux',
} end

let :pre_condition do
Expand Down
30 changes: 20 additions & 10 deletions spec/defines/resource_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
{
:osfamily => 'Debian',
:operatingsystem => 'debian',
:kernel => 'Linux',
:concat_basedir => '/var/lib/puppet/concat',
}
end
let :pre_condition do
Expand All @@ -27,8 +25,8 @@
:vhost => 'vhost1',
} end

it { should include_class("nginx::params") }
it { should include_class("nginx::config") }
it { should contain_class("nginx::params") }
it { should contain_class("nginx::config") }
it { should contain_concat__fragment("vhost1-500-rspec-test").with_content(/location rspec-test/) }
it { should_not contain_file('/etc/nginx/fastcgi_params') }
it { should_not contain_concat__fragment("vhost1-800-rspec-test-ssl") }
Expand Down Expand Up @@ -120,7 +118,9 @@
it param[:title] do
lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n")
(lines & Array(param[:match])).should == Array(param[:match])
(Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty
Array(param[:notmatch]).each do |item|
should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(item)
end
end
end
end
Expand Down Expand Up @@ -181,7 +181,9 @@
it param[:title] do
lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n")
(lines & Array(param[:match])).should == Array(param[:match])
(Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty
Array(param[:notmatch]).each do |item|
should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(item)
end
end
end
end
Expand Down Expand Up @@ -224,7 +226,9 @@
it param[:title] do
lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n")
(lines & Array(param[:match])).should == Array(param[:match])
(Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty
Array(param[:notmatch]).each do |item|
should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(item)
end
end
end
end
Expand Down Expand Up @@ -309,7 +313,9 @@
it param[:title] do
lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n")
(lines & Array(param[:match])).should == Array(param[:match])
(Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty
Array(param[:notmatch]).each do |item|
should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(/#{item}/)
end
end
end
end
Expand Down Expand Up @@ -394,7 +400,9 @@
it param[:title] do
lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n")
(lines & Array(param[:match])).should == Array(param[:match])
(Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty
Array(param[:notmatch]).each do |item|
should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(item)
end
end
end
end
Expand Down Expand Up @@ -427,7 +435,9 @@
it param[:title] do
lines = subject.resource('concat::fragment', "vhost1-500-#{params[:location]}").send(:parameters)[:content].split("\n")
(lines & Array(param[:match])).should == Array(param[:match])
(Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty
Array(param[:notmatch]).each do |item|
should contain_concat__fragment("vhost1-500-#{params[:location]}").without_content(item)
end
end
end
end
Expand Down
Loading