Skip to content

Commit

Permalink
Use rspec-puppet-facts in all places
Browse files Browse the repository at this point in the history
Facts for supported OSes are now loaded from
the rspec-puppet-facts.

Commit includes no changes to any test, they all
just ran as in on top of the various os facts.
  • Loading branch information
traylenator committed Nov 22, 2016
1 parent a58704b commit eb0b708
Show file tree
Hide file tree
Showing 15 changed files with 416 additions and 375 deletions.
2 changes: 0 additions & 2 deletions .sync.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
---
.travis.yml:
secure: "r7NI3OHbyMs/w351LkmkTFFLriDDyWKvgyZt+XYPw7jbaWmqnV4+NSJMQSkXgTS+tq2jNPLOWY1UuPuFJKkyd1m7LteOb2yZ6HJs5BL7QJjJWC2vUjkY60kl2xHn81D6SEXOXoVseGWiimlTlWJM3pKljNgZOZlOMw96vgnd6/I="
spec/spec_helper.rb:
spec_overrides: "require 'spec_helper_methods'"
94 changes: 50 additions & 44 deletions spec/classes/selinux_config_mode_spec.rb
Original file line number Diff line number Diff line change
@@ -1,50 +1,56 @@
require 'spec_helper'

describe 'selinux' do
include_context 'RedHat 7'

context 'config' do
context 'invalid mode' do
let(:params) { { mode: 'invalid' } }
it { expect { is_expected.to create_class('selinux') }.to raise_error(%r{Valid modes are enforcing, permissive, and disabled. Received: invalid}) }
end

context 'undef mode' do
it { is_expected.to have_file_resource_count(1) }
it { is_expected.to have_file_line_resource_count(0) }
it { is_expected.to have_exec_resource_count(0) }

it { is_expected.to contain_file('/usr/share/selinux') }
it { is_expected.not_to contain_file_line('set-selinux-config-to-enforcing') }
it { is_expected.not_to contain_file_line('set-selinux-config-to-permissive') }
it { is_expected.not_to contain_file_line('set-selinux-config-to-disabled') }
it { is_expected.not_to contain_exec('change-selinux-status-to-enforcing') }
it { is_expected.not_to contain_exec('change-selinux-status-to-permissive') }
it { is_expected.not_to contain_exec('change-selinux-status-to-disabled') }
end

context 'enforcing' do
let(:params) { { mode: 'enforcing' } }

it { is_expected.to contain_file('/usr/share/selinux').with(ensure: 'directory') }
it { is_expected.to contain_file_line('set-selinux-config-to-enforcing').with(line: 'SELINUX=enforcing') }
it { is_expected.to contain_exec('change-selinux-status-to-enforcing').with(command: 'setenforce 1') }
end

context 'permissive' do
let(:params) { { mode: 'permissive' } }

it { is_expected.to contain_file('/usr/share/selinux').with(ensure: 'directory') }
it { is_expected.to contain_file_line('set-selinux-config-to-permissive').with(line: 'SELINUX=permissive') }
it { is_expected.to contain_exec('change-selinux-status-to-permissive').with(command: 'setenforce 0') }
end

context 'disabled' do
let(:params) { { mode: 'disabled' } }

it { is_expected.to contain_file('/usr/share/selinux').with(ensure: 'directory') }
it { is_expected.to contain_file_line('set-selinux-config-to-disabled').with(line: 'SELINUX=disabled') }
it { is_expected.to contain_exec('change-selinux-status-to-disabled').with(command: 'setenforce 0') }
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end

context 'config' do
context 'invalid mode' do
let(:params) { { mode: 'invalid' } }
it { expect { is_expected.to create_class('selinux') }.to raise_error(%r{Valid modes are enforcing, permissive, and disabled. Received: invalid}) }
end

context 'undef mode' do
it { is_expected.to have_file_resource_count(1) }
it { is_expected.to have_file_line_resource_count(0) }
it { is_expected.to have_exec_resource_count(0) }

it { is_expected.to contain_file('/usr/share/selinux') }
it { is_expected.not_to contain_file_line('set-selinux-config-to-enforcing') }
it { is_expected.not_to contain_file_line('set-selinux-config-to-permissive') }
it { is_expected.not_to contain_file_line('set-selinux-config-to-disabled') }
it { is_expected.not_to contain_exec('change-selinux-status-to-enforcing') }
it { is_expected.not_to contain_exec('change-selinux-status-to-permissive') }
it { is_expected.not_to contain_exec('change-selinux-status-to-disabled') }
end

context 'enforcing' do
let(:params) { { mode: 'enforcing' } }

it { is_expected.to contain_file('/usr/share/selinux').with(ensure: 'directory') }
it { is_expected.to contain_file_line('set-selinux-config-to-enforcing').with(line: 'SELINUX=enforcing') }
it { is_expected.to contain_exec('change-selinux-status-to-enforcing').with(command: 'setenforce 1') }
end

context 'permissive' do
let(:params) { { mode: 'permissive' } }

it { is_expected.to contain_file('/usr/share/selinux').with(ensure: 'directory') }
it { is_expected.to contain_file_line('set-selinux-config-to-permissive').with(line: 'SELINUX=permissive') }
it { is_expected.to contain_exec('change-selinux-status-to-permissive').with(command: 'setenforce 0') }
end

context 'disabled' do
let(:params) { { mode: 'disabled' } }

it { is_expected.to contain_file('/usr/share/selinux').with(ensure: 'directory') }
it { is_expected.to contain_file_line('set-selinux-config-to-disabled').with(line: 'SELINUX=disabled') }
it { is_expected.to contain_exec('change-selinux-status-to-disabled').with(command: 'setenforce 0') }
end
end
end
end
end
81 changes: 44 additions & 37 deletions spec/classes/selinux_config_type_spec.rb
Original file line number Diff line number Diff line change
@@ -1,44 +1,51 @@
require 'spec_helper'

describe 'selinux' do
include_context 'RedHat 7'

context 'config' do
context 'invalid type' do
let(:params) { { type: 'invalid' } }
it { expect { is_expected.to create_class('selinux') }.to raise_error(%r{Valid types are targeted, minimum, and mls. Received: invalid}) }
end

context 'undef type' do
it { is_expected.to have_file_resource_count(1) }
it { is_expected.to have_file_line_resource_count(0) }
it { is_expected.to have_exec_resource_count(0) }

it { is_expected.to contain_file('/usr/share/selinux') }
it { is_expected.not_to contain_file_line('set-selinux-config-type-to-targeted') }
it { is_expected.not_to contain_file_line('set-selinux-config-type-to-minimum') }
it { is_expected.not_to contain_file_line('set-selinux-config-type-to-mls') }
end

context 'targeted' do
let(:params) { { type: 'targeted' } }

it { is_expected.to contain_file('/usr/share/selinux').with(ensure: 'directory') }
it { is_expected.to contain_file_line('set-selinux-config-type-to-targeted').with(line: 'SELINUXTYPE=targeted') }
end

context 'minimum' do
let(:params) { { type: 'minimum' } }

it { is_expected.to contain_file('/usr/share/selinux').with(ensure: 'directory') }
it { is_expected.to contain_file_line('set-selinux-config-type-to-minimum').with(line: 'SELINUXTYPE=minimum') }
end

context 'mls' do
let(:params) { { type: 'mls' } }

it { is_expected.to contain_file('/usr/share/selinux').with(ensure: 'directory') }
it { is_expected.to contain_file_line('set-selinux-config-type-to-mls').with(line: 'SELINUXTYPE=mls') }
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end
context 'config' do
context 'invalid type' do
let(:params) { { type: 'invalid' } }
it { expect { is_expected.to create_class('selinux') }.to raise_error(%r{Valid types are targeted, minimum, and mls. Received: invalid}) }
end

context 'undef type' do
it { is_expected.to have_file_resource_count(1) }
it { is_expected.to have_file_line_resource_count(0) }
it { is_expected.to have_exec_resource_count(0) }

it { is_expected.to contain_file('/usr/share/selinux') }
it { is_expected.not_to contain_file_line('set-selinux-config-type-to-targeted') }
it { is_expected.not_to contain_file_line('set-selinux-config-type-to-minimum') }
it { is_expected.not_to contain_file_line('set-selinux-config-type-to-mls') }
end

context 'targeted' do
let(:params) { { type: 'targeted' } }

it { is_expected.to contain_file('/usr/share/selinux').with(ensure: 'directory') }
it { is_expected.to contain_file_line('set-selinux-config-type-to-targeted').with(line: 'SELINUXTYPE=targeted') }
end

context 'minimum' do
let(:params) { { type: 'minimum' } }

it { is_expected.to contain_file('/usr/share/selinux').with(ensure: 'directory') }
it { is_expected.to contain_file_line('set-selinux-config-type-to-minimum').with(line: 'SELINUXTYPE=minimum') }
end

context 'mls' do
let(:params) { { type: 'mls' } }

it { is_expected.to contain_file('/usr/share/selinux').with(ensure: 'directory') }
it { is_expected.to contain_file_line('set-selinux-config-type-to-mls').with(line: 'SELINUXTYPE=mls') }
end
end
end
end
end

12 changes: 9 additions & 3 deletions spec/classes/selinux_restorecond_config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
require 'spec_helper'

describe 'selinux::restorecond' do
include_context 'RedHat 7'
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end

it { is_expected.to contain_concat('/etc/selinux/restorecond.conf') }
it { is_expected.to contain_concat__fragment('restorecond_config_default') }
it { is_expected.to contain_concat('/etc/selinux/restorecond.conf') }
it { is_expected.to contain_concat__fragment('restorecond_config_default') }
end
end
end
11 changes: 8 additions & 3 deletions spec/classes/selinux_restorecond_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
require 'spec_helper'

describe 'selinux::restorecond' do
include_context 'RedHat 7'

it { is_expected.to contain_service('restorecond') }
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end
it { is_expected.to contain_service('restorecond') }
end
end
end
14 changes: 10 additions & 4 deletions spec/classes/selinux_restorecond_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
require 'spec_helper'

describe 'selinux::restorecond' do
include_context 'RedHat 7'
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end

it { is_expected.to contain_class('selinux::restorecond') }
it { is_expected.to contain_class('selinux::restorecond::config') }
it { is_expected.to contain_class('selinux::restorecond::service') }
it { is_expected.to contain_class('selinux::restorecond') }
it { is_expected.to contain_class('selinux::restorecond::config') }
it { is_expected.to contain_class('selinux::restorecond::service') }
end
end
end
13 changes: 5 additions & 8 deletions spec/classes/selinux_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
require 'spec_helper'

describe 'selinux' do
[
'RedHat 7',
'CentOS 7',
'Fedora 22'
].each do |ctx|
context ctx do
include_context ctx

on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end
it { is_expected.to contain_class('selinux').without_mode }
it { is_expected.to contain_class('selinux').without_type }
it { is_expected.to contain_class('selinux::package') }
Expand Down
60 changes: 33 additions & 27 deletions spec/defines/selinux_boolean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,42 @@

describe 'selinux::boolean' do
let(:title) { 'mybool' }
include_context 'RedHat 7'

['on', true, 'present'].each do |value|
context value do
let(:params) do
{
ensure: value
}
end
it do
is_expected.to contain_selboolean('mybool').with(
'value' => 'on',
'persistent' => true
)
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end
end
end

['off', false, 'absent'].each do |value|
context value do
let(:params) do
{
ensure: value
}
['on', true, 'present'].each do |value|
context value do
let(:params) do
{
ensure: value
}
end
it do
is_expected.to contain_selboolean('mybool').with(
'value' => 'on',
'persistent' => true
)
end
end
end
it do
is_expected.to contain_selboolean('mybool').with(
'value' => 'off',
'persistent' => true
)

['off', false, 'absent'].each do |value|
context value do
let(:params) do
{
ensure: value
}
end
it do
is_expected.to contain_selboolean('mybool').with(
'value' => 'off',
'persistent' => true
)
end
end
end
end
end
Expand Down
Loading

0 comments on commit eb0b708

Please sign in to comment.