From 63cc300fb2ff662ae5fbd2268001032c0cabba8c Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Fri, 19 Oct 2012 20:14:46 +0200 Subject: update unit tests for osfamily fact --- spec/classes/ntp_spec.rb | 98 ++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 54 deletions(-) (limited to 'spec') diff --git a/spec/classes/ntp_spec.rb b/spec/classes/ntp_spec.rb index 389f085..239f641 100644 --- a/spec/classes/ntp_spec.rb +++ b/spec/classes/ntp_spec.rb @@ -11,80 +11,70 @@ describe 'ntp' do describe 'test platform specific resources' do - debianish = ['debian', 'ubuntu'] - redhatish = ['centos', 'redhat', 'oel', 'linux'] - bsdish = ['freebsd'] - - debianish.each do |os| - describe "for operating system #{os}" do - - let(:params) {{}} - let(:facts) { { :operatingsystem => os } } - - it { should contain_service('ntp').with_name('ntp') } - it 'should use the debian ntp servers by default' do - content = param_value(subject, 'file', '/etc/ntp.conf', 'content') - expected_lines = ['server 0.debian.pool.ntp.org iburst', - 'server 1.debian.pool.ntp.org iburst', - 'server 2.debian.pool.ntp.org iburst', - 'server 3.debian.pool.ntp.org iburst'] - (content.split("\n") & expected_lines).should == expected_lines - end + describe "for operating system family Debian" do + + let(:params) {{}} + let(:facts) { { :osfamily => 'debian' } } + + it { should contain_service('ntp').with_name('ntp') } + it 'should use the debian ntp servers by default' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = ['server 0.debian.pool.ntp.org iburst', + 'server 1.debian.pool.ntp.org iburst', + 'server 2.debian.pool.ntp.org iburst', + 'server 3.debian.pool.ntp.org iburst'] + (content.split("\n") & expected_lines).should == expected_lines end end - redhatish.each do |os| - describe "for operating system #{os}" do + describe "for operating system family RedHat" do - let(:params) {{}} - let(:facts) { { :operatingsystem => os } } + let(:params) {{}} + let(:facts) { { :osfamily => 'redhat' } } - it { should contain_service('ntp').with_name('ntpd') } - it 'should use the redhat ntp servers by default' do - content = param_value(subject, 'file', '/etc/ntp.conf', 'content') - expected_lines = [ - 'server 0.centos.pool.ntp.org', - 'server 1.centos.pool.ntp.org', - 'server 2.centos.pool.ntp.org'] - (content.split("\n") & expected_lines).should == expected_lines - end + it { should contain_service('ntp').with_name('ntpd') } + it 'should use the redhat ntp servers by default' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = [ + 'server 0.centos.pool.ntp.org', + 'server 1.centos.pool.ntp.org', + 'server 2.centos.pool.ntp.org'] + (content.split("\n") & expected_lines).should == expected_lines end end - bsdish.each do |os| - describe "for operating system #{os}" do - - let(:params) {{}} - let(:facts) { { :operatingsystem => os } } - - it { should contain_service('ntp').with_name('ntpd') } - it 'should use the freebsd ntp servers by default' do - content = param_value(subject, 'file', '/etc/ntp.conf', 'content') - expected_lines = [ - "server 0.freebsd.pool.ntp.org iburst maxpoll 9", - "server 1.freebsd.pool.ntp.org iburst maxpoll 9", - "server 2.freebsd.pool.ntp.org iburst maxpoll 9", - "server 3.freebsd.pool.ntp.org iburst maxpoll 9"] - (content.split("\n") & expected_lines).should == expected_lines - end + describe "for operating system family FreeBSD" do + + let(:params) {{}} + let(:facts) { { :osfamily => 'freebsd' } } + + it { should contain_service('ntp').with_name('ntpd') } + it 'should use the freebsd ntp servers by default' do + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') + expected_lines = [ + "server 0.freebsd.pool.ntp.org iburst maxpoll 9", + "server 1.freebsd.pool.ntp.org iburst maxpoll 9", + "server 2.freebsd.pool.ntp.org iburst maxpoll 9", + "server 3.freebsd.pool.ntp.org iburst maxpoll 9"] + (content.split("\n") & expected_lines).should == expected_lines end - describe "for operating system unsupported" do + describe "for operating system family unsupported" do let(:facts) {{ - :operatingsystem => 'unsupported', + :osfamily => 'unsupported', }} it { expect{ subject }.to raise_error( - /^The ntp module is not supported on unsupported/ + /^The ntp module is not supported on unsupported based systems/ )} end end - (redhatish + debianish + bsdish).each do |os| - describe "for operating system #{os}" do + ['Debian', 'RedHat', 'FreeBSD'].each do |osfamily| + describe "for operating system family #{osfamily}" do - let(:facts) { { :operatingsystem => os } } + let(:facts) { { :osfamily => osfamily } } it { should contain_file('/etc/ntp.conf').with_owner('0') } it { should contain_file('/etc/ntp.conf').with_group('0') } -- cgit v1.2.3