Skip to content

Commit

Permalink
(maint) fix specs to run under STRICT_VARIABLES
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidS authored and hunner committed May 9, 2016
1 parent 229dc90 commit f858a47
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
11 changes: 11 additions & 0 deletions spec/spec_helper_local.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
RSpec.configure do |config|
config.mock_with :rspec
end

def with_debian_facts
let :facts do
{
:kernel => 'Linux',
:operatingsystem => 'Debian',
:operatingsystemrelease => '8.0',
:osfamily => 'Debian',
}
end
end
15 changes: 9 additions & 6 deletions spec/unit/classes/firewall_linux_redhat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
:enable => 'true'
)}
end

context 'ensure => stopped' do
let(:params) {{ :ensure => 'stopped' }}
it { should contain_service('iptables').with(
:ensure => 'stopped'
)}
end

context 'enable => false' do
let(:params) {{ :enable => 'false' }}
it { should contain_service('iptables').with(
Expand All @@ -30,24 +31,26 @@
oldreleases.each do |osrel|
context "os #{os} and osrel #{osrel}" do
let(:facts) {{
:osfamily => 'RedHat',
:operatingsystem => os,
:operatingsystemrelease => osrel
:operatingsystemrelease => osrel,
:osfamily => 'RedHat',
:selinux => false,
}}

it { should_not contain_service('firewalld') }
it { should_not contain_package('iptables-services') }

it_behaves_like "ensures iptables service"
end
end

newreleases.each do |osrel|
context "os #{os} and osrel #{osrel}" do
let(:facts) {{
:osfamily => 'RedHat',
:operatingsystem => os,
:operatingsystemrelease => osrel
:operatingsystemrelease => osrel,
:osfamily => 'RedHat',
:selinux => false,
}}

it { should contain_service('firewalld').with(
Expand Down
23 changes: 17 additions & 6 deletions spec/unit/classes/firewall_linux_spec.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
require 'spec_helper'

describe 'firewall::linux', :type => :class do
let(:facts_default) {{ :kernel => 'Linux' }}
it { should contain_package('iptables').with_ensure('present') }

context 'RedHat like' do
%w{RedHat CentOS Fedora}.each do |os|
context "operatingsystem => #{os}" do
releases = (os == 'Fedora' ? ['14','15','Rawhide'] : ['6','7'])
releases.each do |osrel|
context "operatingsystemrelease => #{osrel}" do
let(:facts) { facts_default.merge({ :operatingsystem => os,
:operatingsystemrelease => osrel}) }
let(:facts) {{
:kernel => 'Linux',
:operatingsystem => os,
:operatingsystemrelease => osrel,
:osfamily => 'RedHat',
:selinux => false,
}}
it { should contain_class('firewall::linux::redhat').with_require('Package[iptables]') }
it { should contain_package('iptables').with_ensure('present') }
end
end
end
Expand All @@ -24,8 +27,16 @@
context "operatingsystem => #{os}" do
releases = (os == 'Debian' ? ['6','7','8'] : ['10.04','12.04','14.04'])
releases.each do |osrel|
let(:facts) { facts_default.merge({ :operatingsystem => os, :operatingsystemrelease => osrel}) }
let(:facts) {{
:kernel => 'Linux',
:operatingsystem => os,
:operatingsystemrelease => osrel,
:osfamily => 'Debian',
:selinux => false,
}}

it { should contain_class('firewall::linux::debian').with_require('Package[iptables]') }
it { should contain_package('iptables').with_ensure('present') }
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/classes/firewall_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'firewall', :type => :class do
context 'kernel => Linux' do
let(:facts) {{ :kernel => 'Linux' }}
with_debian_facts
it { should contain_class('firewall::linux').with_ensure('running') }
end

Expand All @@ -22,7 +22,7 @@
end

context 'ensure => stopped' do
let(:facts) {{ :kernel => 'Linux' }}
with_debian_facts
let(:params) {{ :ensure => 'stopped' }}
it { should contain_class('firewall::linux').with_ensure('stopped') }
end
Expand Down

0 comments on commit f858a47

Please sign in to comment.