newer pg module
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / unit / defines / server / database_spec.rb
1 require 'spec_helper'
2
3 describe 'postgresql::server::database', :type => :define do
4   let :facts do
5     {
6       :osfamily => 'Debian',
7       :operatingsystem => 'Debian',
8       :operatingsystemrelease => '6.0',
9       :kernel => 'Linux',
10       :concat_basedir => tmpfilename('contrib'),
11       :id => 'root',
12       :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
13     }
14   end
15   let :title do
16     'test'
17   end
18
19   let :pre_condition do
20     "class {'postgresql::server':}"
21   end
22
23   it { is_expected.to contain_postgresql__server__database('test') }
24   it { is_expected.to contain_postgresql_psql('CREATE DATABASE "test"') }
25
26   context "with comment set to 'test comment'" do
27     let (:params) {{ :comment => 'test comment' }}
28
29     it { is_expected.to contain_postgresql_psql("COMMENT ON DATABASE \"test\" IS 'test comment'").with_connect_settings( {} ) }
30   end
31
32   context "with specific db connection settings - default port" do
33     let :pre_condition do
34       "class {'postgresql::server':}"
35     end
36
37     let (:params) {{ :connect_settings => { 'PGHOST'    => 'postgres-db-server',
38                                             'DBVERSION' => '9.1', }}}
39
40     it { is_expected.to contain_postgresql_psql('CREATE DATABASE "test"').with_connect_settings( { 'PGHOST'    => 'postgres-db-server','DBVERSION' => '9.1' } ).with_port( 5432 ) }
41   end
42
43   context "with specific db connection settings - including port" do
44     let :pre_condition do
45       "class {'postgresql::globals':}
46
47        class {'postgresql::server':}"
48     end
49
50     let (:params) {{ :connect_settings => { 'PGHOST'    => 'postgres-db-server',
51                                             'DBVERSION' => '9.1',
52                                             'PGPORT'    => '1234' }}}
53
54     it { is_expected.to contain_postgresql_psql('CREATE DATABASE "test"').with_connect_settings( { 'PGHOST'    => 'postgres-db-server','DBVERSION' => '9.1','PGPORT'    => '1234' } ).with_port( nil ) }
55
56   end
57
58   context "with global db connection settings - including port" do
59     let :pre_condition do
60       "class {'postgresql::globals':
61            default_connect_settings => { 'PGHOST'    => 'postgres-db-server',
62                                          'DBVERSION' => '9.2',
63                                          'PGPORT'    => '1234' }
64        }
65
66        class {'postgresql::server':}"
67     end
68
69     it { is_expected.to contain_postgresql_psql('CREATE DATABASE "test"').with_connect_settings( { 'PGHOST'    => 'postgres-db-server','DBVERSION' => '9.2','PGPORT'    => '1234' } ).with_port( nil ) }
70
71   end
72
73   context "with different owner" do
74     let (:params) {{ :owner => 'test_owner' }}
75
76     it { is_expected.to contain_postgresql_psql('ALTER DATABASE "test" OWNER TO "test_owner"') }
77   end
78 end