diff --git a/spec/classes/client_spec.rb b/spec/classes/client_spec.rb index 80115b3..362d4b2 100644 --- a/spec/classes/client_spec.rb +++ b/spec/classes/client_spec.rb @@ -1,55 +1,51 @@ require 'spec_helper' describe 'ssh::client', type: 'class' do context 'when on Debian with no other parameters' do let :facts do { :os => { 'family' => 'Debian' }, 'networking' => { 'interfaces' => { 'eth0' => { 'ip' => '10.0.0.1' }, 'eth1' => { 'ip' => '10.0.1.1' }, } } } end - it do - is_expected.to contain_package('openssh-client').with(ensure: 'present') - end + it { is_expected.to contain_package('openssh-client').with_ensure('installed') } end context 'when on Debian with custom ensure' do let :facts do { :os => { 'family' => 'Debian' }, 'networking' => { 'interfaces' => { 'eth0' => { 'ip' => '10.0.0.1' }, 'eth1' => { 'ip' => '10.0.1.1' }, } } } end let :params do { ensure: 'latest' } end - it do - is_expected.to contain_package('openssh-client').with(ensure: 'latest') - end + it { is_expected.to contain_package('openssh-client').with_ensure('latest') } end end diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 54d977e..ea79d80 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -1,181 +1,188 @@ require 'spec_helper' describe 'ssh::server' do let :default_params do { ensure: 'present', storeconfigs_enabled: true } end describe 'providing options' do let :params do { options: { 'TestString' => '/usr/bin', 'TestBoolean' => true } } end let :facts do { :os => { 'family' => 'RedHat', 'release' => { 'major' => '6' } }, 'networking' => { 'interfaces' => { 'eth0' => { 'ip' => '10.0.0.1' }, 'eth1' => { 'ip' => '10.0.1.1' }, } } } end it do is_expected.to contain_concat__fragment('global config').with( target: '/etc/ssh/sshd_config', content: '# File is managed by Puppet AcceptEnv LANG LC_* ChallengeResponseAuthentication no PrintMotd no Subsystem sftp /usr/libexec/openssh/sftp-server TestBoolean yes TestString /usr/bin UsePAM yes X11Forwarding yes ' # rubocop:enable EmptyLinesAroundArguments ) end end [{}, { ensure: 'latest', storeconfigs_enabled: true }, { ensure: 'present', storeconfigs_enabled: false }].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 param_set end ['Debian'].each do |osfamily| let :facts do { :os => { 'family' => osfamily }, 'networking' => { 'interfaces' => { 'eth0' => { 'ip' => '10.0.0.1' }, 'eth1' => { 'ip' => '10.0.1.1' }, } } } end describe "on supported osfamily: #{osfamily}" do it { is_expected.to contain_class('ssh::params') } - it { is_expected.to contain_package('openssh-server').with_ensure(param_hash[:ensure]) } + it do + if param_hash[:ensure] == 'present' + is_expected.to contain_package('openssh-server').with_ensure('installed') + else + is_expected.to contain_package('openssh-server').with_ensure(param_hash[:ensure]) + end + end it do is_expected.to contain_service('ssh').with( 'ensure' => 'running', 'enable' => true, 'hasrestart' => true, 'hasstatus' => true ) end it { is_expected.to contain_concat('/etc/ssh/sshd_config') } it do is_expected.to contain_concat__fragment('global config').with( target: '/etc/ssh/sshd_config', content: '# File is managed by Puppet AcceptEnv LANG LC_* ChallengeResponseAuthentication no PrintMotd no Subsystem sftp /usr/lib/openssh/sftp-server UsePAM yes X11Forwarding yes ' ) end end describe 'on Arch' do let :facts do { :os => { 'family' => 'Archlinux' }, 'networking' => { 'interfaces' => { 'eth0' => { 'ip' => '10.0.0.1' }, 'eth1' => { 'ip' => '10.0.1.1' }, } } } end it { is_expected.to contain_class('ssh::params') } it do - is_expected.to contain_package('openssh').with( - ensure: param_hash[:ensure], - name: 'openssh' - ) + if param_hash[:ensure] == 'present' + is_expected.to contain_package('openssh').with_ensure('installed').with(name: 'openssh') + else + is_expected.to contain_package('openssh').with_ensure(param_hash[:ensure]).with(name: 'openssh') + end end it do is_expected.to contain_service('sshd.service').with( 'ensure' => 'running', 'enable' => true, 'hasrestart' => true, 'hasstatus' => true ) end it { is_expected.to contain_concat('/etc/ssh/sshd_config') } it do is_expected.to contain_concat__fragment('global config').with( target: '/etc/ssh/sshd_config', content: '# File is managed by Puppet AcceptEnv LANG LC_* ChallengeResponseAuthentication no PrintMotd no Subsystem sftp /usr/lib/ssh/sftp-server UsePAM yes X11Forwarding yes ' ) end end end end end end