|
| 1 | +#!/usr/bin/env rspec |
| 2 | +require 'spec_helper' |
| 3 | + |
| 4 | +describe 'ntp' do |
| 5 | + |
| 6 | + def param_value(subject, type, title, param) |
| 7 | + catalogue.resource(type, title).send(:parameters)[param.to_sym] |
| 8 | + end |
| 9 | + |
| 10 | + let(:params) { {:servers => 'fake.pool.ntp.org'} } |
| 11 | + |
| 12 | + describe 'test platform specific resources' do |
| 13 | + |
| 14 | + debianish = ['debian', 'ubuntu'] |
| 15 | + redhatish = ['centos', 'redhat', 'oel', 'linux'] |
| 16 | + |
| 17 | + debianish.each do |os| |
| 18 | + describe "for operating system #{os}" do |
| 19 | + |
| 20 | + let(:params) {{}} |
| 21 | + let(:facts) { { :operatingsystem => os } } |
| 22 | + |
| 23 | + it { should contain_service('ntp').with_name('ntp') } |
| 24 | + it 'should use the debian ntp servers by default' do |
| 25 | + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') |
| 26 | + expected_lines = ['server 0.debian.pool.ntp.org iburst', |
| 27 | + 'server 1.debian.pool.ntp.org iburst', |
| 28 | + 'server 2.debian.pool.ntp.org iburst', |
| 29 | + 'server 3.debian.pool.ntp.org iburst'] |
| 30 | + (content.split("\n") & expected_lines).should == expected_lines |
| 31 | + end |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + redhatish.each do |os| |
| 36 | + describe "for operating system #{os}" do |
| 37 | + |
| 38 | + let(:params) {{}} |
| 39 | + let(:facts) { { :operatingsystem => os } } |
| 40 | + |
| 41 | + it { should contain_service('ntp').with_name('ntpd') } |
| 42 | + it 'should use the redhat ntp servers by default' do |
| 43 | + content = param_value(subject, 'file', '/etc/ntp.conf', 'content') |
| 44 | + expected_lines = [ |
| 45 | + 'server 0.centos.pool.ntp.org', |
| 46 | + 'server 1.centos.pool.ntp.org', |
| 47 | + 'server 2.centos.pool.ntp.org'] |
| 48 | + (content.split("\n") & expected_lines).should == expected_lines |
| 49 | + end |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + (redhatish + debianish).each do |os| |
| 54 | + describe "for operating system #{os}" do |
| 55 | + |
| 56 | + let(:facts) { { :operatingsystem => os } } |
| 57 | + |
| 58 | + it { should contain_file('/etc/ntp.conf').with_owner('0') } |
| 59 | + it { should contain_file('/etc/ntp.conf').with_group('0') } |
| 60 | + it { should contain_file('/etc/ntp.conf').with_mode('0644') } |
| 61 | + it { should contain_package('ntp').with_ensure('present') } |
| 62 | + it { should contain_service('ntp').with_ensure('running') } |
| 63 | + it { should contain_service('ntp').with_hasstatus(true) } |
| 64 | + it { should contain_service('ntp').with_hasrestart(true) } |
| 65 | + it 'should allow service ensure to be overridden' do |
| 66 | + params[:ensure] = 'stopped' |
| 67 | + subject.should contain_service('ntp').with_ensure('stopped') |
| 68 | + end |
| 69 | + it 'should allow package ensure to be overridden' do |
| 70 | + params[:autoupdate] = true |
| 71 | + subject.should contain_package('ntp').with_ensure('latest') |
| 72 | + end |
| 73 | + end |
| 74 | + end |
| 75 | + end |
| 76 | +end |
0 commit comments