newer pg module
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / unit / classes / server / config_spec.rb
1 require 'spec_helper'
2
3 describe 'postgresql::server::config', :type => :class do
4   let (:pre_condition) do
5     "include postgresql::server"
6   end
7
8   describe 'on RedHat 7' do
9     let :facts do
10       {
11         :osfamily => 'RedHat',
12         :operatingsystem => 'CentOS',
13         :operatingsystemrelease => '7.0',
14         :concat_basedir => tmpfilename('server'),
15         :kernel => 'Linux',
16         :id => 'root',
17         :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
18         :selinux => true,
19       }
20     end
21     it 'should have the correct systemd-override file' do
22       is_expected.to contain_file('systemd-override').with ({
23         :ensure => 'present',
24         :path => '/etc/systemd/system/postgresql.service',
25         :owner => 'root',
26         :group => 'root',
27       })
28       is_expected.to contain_file('systemd-override') \
29         .with_content(/.include \/usr\/lib\/systemd\/system\/postgresql.service/)
30     end
31
32     describe 'with manage_package_repo => true and a version' do
33       let (:pre_condition) do
34         <<-EOS
35           class { 'postgresql::globals':
36             manage_package_repo => true,
37             version => '9.4',
38           }->
39           class { 'postgresql::server': }
40         EOS
41       end
42
43       it 'should have the correct systemd-override file' do
44         is_expected.to contain_file('systemd-override').with ({
45           :ensure => 'present',
46           :path => '/etc/systemd/system/postgresql-9.4.service',
47           :owner => 'root',
48           :group => 'root',
49         })
50         is_expected.to contain_file('systemd-override') \
51           .with_content(/.include \/usr\/lib\/systemd\/system\/postgresql-9.4.service/)
52       end
53     end
54   end
55
56   describe 'on Fedora 21' do
57     let :facts do
58       {
59         :osfamily => 'RedHat',
60         :operatingsystem => 'Fedora',
61         :operatingsystemrelease => '21',
62         :concat_basedir => tmpfilename('server'),
63         :kernel => 'Linux',
64         :id => 'root',
65         :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
66         :selinux => true,
67       }
68     end
69     it 'should have the correct systemd-override file' do
70       is_expected.to contain_file('systemd-override').with ({
71         :ensure => 'present',
72         :path => '/etc/systemd/system/postgresql.service',
73         :owner => 'root',
74         :group => 'root',
75       })
76       is_expected.to contain_file('systemd-override') \
77         .with_content(/.include \/lib\/systemd\/system\/postgresql.service/)
78     end
79
80     describe 'with manage_package_repo => true and a version' do
81       let (:pre_condition) do
82         <<-EOS
83           class { 'postgresql::globals':
84             manage_package_repo => true,
85             version => '9.4',
86           }->
87           class { 'postgresql::server': }
88         EOS
89       end
90
91       it 'should have the correct systemd-override file' do
92         is_expected.to contain_file('systemd-override').with ({
93           :ensure => 'present',
94           :path => '/etc/systemd/system/postgresql-9.4.service',
95           :owner => 'root',
96           :group => 'root',
97         })
98         is_expected.to contain_file('systemd-override') \
99           .with_content(/.include \/lib\/systemd\/system\/postgresql-9.4.service/)
100       end
101     end
102   end
103
104   describe 'on Gentoo' do
105     let (:pre_condition) do
106       <<-EOS
107         class { 'postgresql::globals':
108           version => '9.5',
109         }->
110         class { 'postgresql::server': }
111       EOS
112     end
113     let :facts do
114       {
115         :osfamily => 'Gentoo',
116         :operatingsystem => 'Gentoo',
117         :operatingsystemrelease => 'unused',
118         :concat_basedir => tmpfilename('server'),
119         :kernel => 'Linux',
120         :id => 'root',
121         :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
122         :selinux => false,
123       }
124     end
125     it 'should have the correct systemd-override file' do
126       is_expected.to contain_file('systemd-override').with ({
127         :ensure => 'present',
128         :path => '/etc/systemd/system/postgresql-9.5.service',
129         :owner => 'root',
130         :group => 'root',
131       })
132       is_expected.to contain_file('systemd-override') \
133         .with_content(/.include \/usr\/lib64\/systemd\/system\/postgresql-9.5.service/)
134     end
135   end
136
137   describe 'with managed pg_hba_conf and ipv4acls' do
138     let (:pre_condition) do
139       <<-EOS
140         class { 'postgresql::globals':
141           version => '9.5',
142         }->
143         class { 'postgresql::server':
144           manage_pg_hba_conf => true,
145           ipv4acls => [
146             'hostnossl all all 0.0.0.0/0 reject',
147             'hostssl all all 0.0.0.0/0 md5'
148           ]
149         }
150       EOS
151     end
152     let :facts do
153       {
154         :osfamily => 'RedHat',
155         :operatingsystem => 'CentOS',
156         :operatingsystemrelease => '7.0',
157         :concat_basedir => tmpfilename('server'),
158         :kernel => 'Linux',
159         :id => 'root',
160         :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
161         :selinux => true,
162       }
163     end
164     it 'should have hba rule default' do
165       is_expected.to contain_postgresql__server__pg_hba_rule('local access as postgres user')
166     end
167     it 'should have hba rule ipv4acls' do
168       is_expected.to contain_postgresql__server__pg_hba_rule('postgresql class generated rule ipv4acls 0')
169     end
170   end
171 end