summaryrefslogtreecommitdiff
path: root/spec/classes/ntp_spec.rb
blob: 239f641fbe6b4a2b27d44ac65a02b1d3f2ff0902 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env rspec
require 'spec_helper'

describe 'ntp' do

  def param_value(subject, type, title, param)
    catalogue.resource(type, title).send(:parameters)[param.to_sym]
  end

  let(:params) { {:servers => 'fake.pool.ntp.org'}  }

  describe 'test platform specific resources' do

    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

    describe "for operating system family RedHat" do

      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
    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 family unsupported" do
        let(:facts) {{
          :osfamily  => 'unsupported',
        }}

        it { expect{ subject }.to raise_error(
          /^The ntp module is not supported on unsupported based systems/
        )}
      end

    end

    ['Debian', 'RedHat', 'FreeBSD'].each do |osfamily|
      describe "for operating system family #{osfamily}" do

        let(:facts) { { :osfamily => osfamily } }

        it { should contain_file('/etc/ntp.conf').with_owner('0') }
        it { should contain_file('/etc/ntp.conf').with_group('0') }
        it { should contain_file('/etc/ntp.conf').with_mode('0644') }
        it { should contain_package('ntp').with_ensure('present') }
        it { should contain_service('ntp').with_ensure('running') }
        it { should contain_service('ntp').with_hasstatus(true) }
        it { should contain_service('ntp').with_hasrestart(true) }
        it 'should allow service ensure to be overridden' do
          params[:ensure] = 'stopped'
          subject.should contain_service('ntp').with_ensure('stopped')
        end
        it 'should allow package ensure to be overridden' do
          params[:autoupdate] = true
          subject.should contain_package('ntp').with_ensure('latest')
        end
      end
    end
  end
end