newer pg module
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / unit / classes / server / initdb_spec.rb
1 require 'spec_helper'
2
3 describe 'postgresql::server::initdb', :type => :class do
4   let (:pre_condition) do
5     "include postgresql::server"
6   end
7   describe 'on RedHat' do
8     let :facts do
9       {
10         :osfamily => 'RedHat',
11         :operatingsystem => 'CentOS',
12         :operatingsystemrelease => '6.0',
13         :concat_basedir => tmpfilename('server'),
14         :kernel => 'Linux',
15         :id => 'root',
16         :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
17         :selinux => true,
18       }
19     end
20     it { is_expected.to contain_file('/var/lib/pgsql/data').with_ensure('directory') }
21   end
22   describe 'on Amazon' do
23     let :facts do
24       {
25         :osfamily => 'RedHat',
26         :operatingsystem => 'Amazon',
27         :operatingsystemrelease => '1.0',
28         :concat_basedir => tmpfilename('server'),
29         :kernel => 'Linux',
30         :id => 'root',
31         :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
32         :selinux => true,
33       }
34     end
35     it { is_expected.to contain_file('/var/lib/pgsql92/data').with_ensure('directory') }
36   end
37
38   describe 'exec with module_workdir => /var/tmp' do
39     let :facts do
40       {
41         :osfamily => 'RedHat',
42         :operatingsystem => 'CentOS',
43         :operatingsystemrelease => '6.0',
44         :concat_basedir => tmpfilename('server'),
45         :kernel => 'Linux',
46         :id => 'root',
47         :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
48         :selinux => true,
49       }
50     end
51     let (:pre_condition) do
52       <<-EOS
53         class { 'postgresql::globals':
54           module_workdir => '/var/tmp',
55         }->
56         class { 'postgresql::server': }
57       EOS
58     end
59
60     it 'should contain exec with specified working directory' do
61       is_expected.to contain_exec('postgresql_initdb').with ({
62         :cwd => '/var/tmp',
63       })
64     end
65   end
66
67   describe 'exec with module_workdir => undef' do
68     let :facts do
69       {
70         :osfamily => 'RedHat',
71         :operatingsystem => 'CentOS',
72         :operatingsystemrelease => '6.0',
73         :concat_basedir => tmpfilename('server'),
74         :kernel => 'Linux',
75         :id => 'root',
76         :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
77         :selinux => true,
78       }
79     end
80     let (:pre_condition) do
81       <<-EOS
82         class { 'postgresql::globals':
83         }->
84         class { 'postgresql::server': }
85       EOS
86     end
87
88     it 'should contain exec with default working directory' do
89       is_expected.to contain_exec('postgresql_initdb').with ({
90         :cwd => '/tmp',
91       })
92     end
93   end
94
95
96   describe 'postgresql_psql with module_workdir => /var/tmp' do
97     let :facts do
98       {
99         :osfamily => 'RedHat',
100         :operatingsystem => 'CentOS',
101         :operatingsystemrelease => '6.0',
102         :concat_basedir => tmpfilename('server'),
103         :kernel => 'Linux',
104         :id => 'root',
105         :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
106         :selinux => true,
107       }
108     end
109
110     let (:pre_condition) do
111       <<-EOS
112         class { 'postgresql::globals':
113           module_workdir => '/var/tmp',
114           encoding       => 'test',
115           needs_initdb   => false,
116         }->
117         class { 'postgresql::server': }
118       EOS
119     end
120     it 'should contain postgresql_psql with specified working directory' do 
121       is_expected.to contain_postgresql_psql('Set template1 encoding to test').with({
122         :cwd => '/var/tmp',
123       })
124     end
125   end
126 end
127