Add actual postgresl module from puppetlabs
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / system / non_defaults_spec.rb
1 require 'spec_helper_system'
2
3 describe 'non defaults:' do
4   before :all do
5     puppet_apply(<<-EOS)
6       if($::operatingsystem =~ /Debian|Ubuntu/) {
7         # Need to make sure the correct utf8 locale is ready for our
8         # non-standard tests
9         file { '/etc/locale.gen':
10           content => "en_US ISO-8859-1\nen_NG UTF-8\nen_US UTF-8\n",
11         }~>
12         exec { '/usr/sbin/locale-gen':
13           logoutput => true,
14           refreshonly => true,
15         }
16       }
17     EOS
18   end
19
20   context 'test installing non-default version of postgresql' do
21     after :each do
22       # Cleanup
23       psql('--command="drop database postgresql_test_db" postgres')
24       pp = <<-EOS
25         class { "postgresql":
26           version              => "9.2",
27           manage_package_repo  => true,
28         }->
29         class { 'postgresql::server':
30           ensure => absent,
31           service_status => 'service postgresql-9.2 status',
32         }
33       EOS
34       puppet_apply(pp)
35     end
36
37     it 'perform installation and create a db' do
38       pp = <<-EOS
39         # Configure version and manage_package_repo globally, install postgres
40         # and then try to install a new database.
41         class { "postgresql":
42           version              => "9.2",
43           manage_package_repo  => true,
44           charset              => 'UTF8',
45           locale               => 'en_US.UTF-8',
46         }->
47         class { "postgresql::server": }->
48         postgresql::db { "postgresql_test_db":
49           user        => "foo1",
50           password    => postgresql_password('foo1', 'foo1'),
51         }->
52         class { "postgresql::plperl": }
53       EOS
54
55       puppet_apply(pp) do |r|
56         # Currently puppetlabs/apt shows deprecated messages
57         #r.stderr.should be_empty
58         [2,6].should include(r.exit_code)
59       end
60
61       puppet_apply(pp) do |r|
62         # Currently puppetlabs/apt shows deprecated messages
63         #r.stderr.should be_empty
64         # It also returns a 4
65         [0,4].should include(r.exit_code)
66       end
67
68       psql('postgresql_test_db --command="select datname from pg_database limit 1"')
69     end
70   end
71
72   context 'override locale and charset' do
73     it 'perform installation with different locale and charset' do
74       puts node.facts.inspect
75       pending('no support for locale parameter with centos 5', :if => (node.facts['osfamily'] == 'RedHat' and node.facts['lsbmajdistrelease'] == '5'))
76       pending('no support for initdb with debian/ubuntu', :if => (node.facts['osfamily'] == 'Debian'))
77
78       # TODO: skip for ubuntu and centos 5
79       pp = <<-EOS
80         # Set global locale and charset option, and try installing postgres
81         class { 'postgresql':
82           locale  => 'en_NG',
83           charset => 'UTF8',
84         }->
85         class { 'postgresql::server': }
86       EOS
87
88       puppet_apply(pp) do |r|
89         # Currently puppetlabs/apt shows deprecated messages
90         #r.stderr.should be_empty
91         # It also returns a 6
92         [2,6].should include(r.exit_code)
93       end
94
95       puppet_apply(pp) do |r|
96         # Currently puppetlabs/apt shows deprecated messages
97         #r.stderr.should be_empty
98         # It also returns a 2
99         [0,4].should include(r.exit_code)
100       end
101
102       # Remove db first, if it exists for some reason
103       shell('su postgres -c "dropdb test1"')
104       shell('su postgres -c "createdb test1"')
105       shell('su postgres -c \'psql -c "show lc_ctype" test1\'') do |r|
106         r.stdout.should =~ /en_NG/
107       end
108
109       shell('su postgres -c \'psql -c "show lc_collate" test1\'') do |r|
110         r.stdout.should =~ /en_NG/
111       end
112     end
113   end
114 end