newer pg module
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / unit / defines / server / extension_spec.rb
1 require 'spec_helper'
2
3 describe 'postgresql::server::extension', :type => :define do
4   let :pre_condition do
5     "class { 'postgresql::server': }
6      postgresql::server::database { 'template_postgis':
7        template   => 'template1',
8      }"
9   end
10
11   let :facts do
12     {
13       :osfamily => 'Debian',
14       :operatingsystem => 'Debian',
15       :operatingsystemrelease => '6.0',
16       :kernel => 'Linux',
17       :concat_basedir => tmpfilename('postgis'),
18       :id => 'root',
19       :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
20     }
21   end
22
23   let (:title) { 'postgis' }
24   let (:params) { {
25     :database => 'template_postgis',
26   } }
27
28   context "with mandatory arguments only" do
29     it {
30       is_expected.to contain_postgresql_psql('Add postgis extension to template_postgis').with({
31         :db      => 'template_postgis',
32         :command => 'CREATE EXTENSION "postgis"',
33         :unless  => "SELECT t.count FROM (SELECT count(extname) FROM pg_extension WHERE extname = 'postgis') as t WHERE t.count = 1",
34       }).that_requires('Postgresql::Server::Database[template_postgis]')
35     }
36   end
37
38   context "when setting package name" do
39     let (:params) { super().merge({
40       :package_name => 'postgis',
41     }) }
42
43     it {
44       is_expected.to contain_package('postgis').with({
45         :ensure  => 'present',
46         :name    => 'postgis',
47       }).that_comes_before('Postgresql_psql[Add postgis extension to template_postgis]')
48     }
49   end
50
51   context "when ensuring absence" do
52     let (:params) { super().merge({
53       :ensure       => 'absent',
54       :package_name => 'postgis',
55     }) }
56
57     it {
58       is_expected.to contain_postgresql_psql('Add postgis extension to template_postgis').with({
59         :db      => 'template_postgis',
60         :command => 'DROP EXTENSION "postgis"',
61         :unless  => "SELECT t.count FROM (SELECT count(extname) FROM pg_extension WHERE extname = 'postgis') as t WHERE t.count != 1",
62       }).that_requires('Postgresql::Server::Database[template_postgis]')
63     }
64
65     it {
66       is_expected.to contain_package('postgis').with({
67         :ensure  => 'absent',
68         :name    => 'postgis',
69       })
70     }
71
72     context "when keeping package installed" do
73       let (:params) { super().merge({
74         :package_ensure => 'present',
75       }) }
76
77       it {
78         is_expected.to contain_postgresql_psql('Add postgis extension to template_postgis').with({
79           :db      => 'template_postgis',
80           :command => 'DROP EXTENSION "postgis"',
81           :unless  => "SELECT t.count FROM (SELECT count(extname) FROM pg_extension WHERE extname = 'postgis') as t WHERE t.count != 1",
82         }).that_requires('Postgresql::Server::Database[template_postgis]')
83       }
84
85       it {
86         is_expected.to contain_package('postgis').with({
87           :ensure  => 'present',
88           :name    => 'postgis',
89         }).that_requires('Postgresql_psql[Add postgis extension to template_postgis]')
90       }
91     end
92   end
93 end
94
95 describe 'postgresql::server::extension', :type => :define do
96   let :pre_condition do
97     "class { 'postgresql::server': }
98      postgresql::server::database { 'template_postgis2':
99        template   => 'template1',
100      }"
101   end
102
103   let :facts do
104     {
105       :osfamily => 'Debian',
106       :operatingsystem => 'Debian',
107       :operatingsystemrelease => '6.0',
108       :kernel => 'Linux',
109       :concat_basedir => tmpfilename('postgis'),
110       :id => 'root',
111       :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
112     }
113   end
114
115   let (:title) { 'postgis_db2' }
116   let (:params) { {
117     :database => 'template_postgis2',
118     :extension => 'postgis',
119   } }
120
121   context "with mandatory arguments only" do
122     it {
123       is_expected.to contain_postgresql_psql('Add postgis extension to template_postgis2').with({
124         :db      => 'template_postgis2',
125         :command => 'CREATE EXTENSION "postgis"',
126         :unless  => "SELECT t.count FROM (SELECT count(extname) FROM pg_extension WHERE extname = 'postgis') as t WHERE t.count = 1",
127       }).that_requires('Postgresql::Server::Database[template_postgis2]')
128     }
129   end
130 end