Skip to content

Commit

Permalink
improve spec test
Browse files Browse the repository at this point in the history
  • Loading branch information
saz committed Mar 13, 2014
1 parent e46a32b commit 37fd998
Showing 1 changed file with 69 additions and 24 deletions.
93 changes: 69 additions & 24 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,78 @@
require 'spec_helper'

describe 'ssh::server', :type => 'class' do
context "On Debian with no other parameters" do
let :facts do
describe 'ssh::server' do
let :default_params do
{
:osfamily => 'Debian',
:interfaces => 'eth0',
:ipaddress_eth0 => '192.168.1.1'
}
end
it {
should contain_package('openssh-server').with(:ensure => 'present')
:ensure => 'present',
:storeconfigs_enabled => true,
:options => {}
}
end
context "On Debian with custom ensure" do
let :facts do
{
:osfamily => 'Debian',
:interfaces => 'eth0',
:ipaddress_eth0 => '192.168.1.1'
}

[ {},
{
:ensure => 'latest',
:storeconfigs_enabled => true,
:options => {}
},
{
:ensure => 'present',
:storeconfigs_enabled => false,
:options => {}
}
].each do |param_set|
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
let :param_hash do
default_params.merge(param_set)
end

let :params do
{
:ensure => 'latest'
}
param_set
end
it {
should contain_package('openssh-server').with(:ensure => 'latest')
}

['Debian'].each do |osfamily|
let :facts do
{
:osfamily => osfamily,
:interfaces => 'eth0',
:ipaddress_eth0 => '192.168.1.1'
}
end

describe "on supported osfamily: #{osfamily}" do
it { should contain_class('ssh::params') }
it { should contain_package('openssh-server').with_ensure(param_hash[:ensure]) }

it { should contain_file('/etc/ssh/sshd_config').with(
'owner' => 0,
'group' => 0,
)}

it { should contain_service('ssh').with(
'ensure' => 'running',
'enable' => true,
'hasrestart' => true,
'hasstatus' => true,
)}

it 'should compile the template based on the class parameters' do
content = param_value(
subject,
'file',
'/etc/ssh/sshd_config',
'content'
)
expected_lines = [
'ChallengeResponseAuthentication no',
'X11Forwarding yes',
'PrintMotd no',
'AcceptEnv LANG LC_*',
'Subsystem sftp /usr/lib/openssh/sftp-server',
'UsePAM yes'
]
(content.split("\n") & expected_lines).should =~ expected_lines
end
end
end
end
end
end

0 comments on commit 37fd998

Please sign in to comment.