Added modules
This commit is contained in:
parent
c53c931217
commit
59ec520742
646 changed files with 35182 additions and 0 deletions
18
modules/postgresql/spec/acceptance/client_spec.rb
Normal file
18
modules/postgresql/spec/acceptance/client_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::client:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::client': package_ensure => purged }",
|
||||
:catch_failures => true)
|
||||
end
|
||||
|
||||
it 'test loading class with no parameters' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::client': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
47
modules/postgresql/spec/acceptance/common_patterns_spec.rb
Normal file
47
modules/postgresql/spec/acceptance/common_patterns_spec.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'common patterns:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
describe 'postgresql.conf include pattern' do
|
||||
after :all do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': ensure => absent }
|
||||
|
||||
file { '/tmp/include.conf':
|
||||
ensure => absent
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it "should support an 'include' directive at the end of postgresql.conf" do
|
||||
pending('no support for include directive with centos 5/postgresql 8.1',
|
||||
:if => (fact('osfamily') == 'RedHat' and fact('lsbmajdistrelease') == '5'))
|
||||
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
$extras = "/etc/postgresql-include.conf"
|
||||
|
||||
file { $extras:
|
||||
content => 'max_connections = 123',
|
||||
seltype => 'postgresql_db_t',
|
||||
seluser => 'system_u',
|
||||
notify => Class['postgresql::server::service'],
|
||||
}
|
||||
|
||||
postgresql::server::config_entry { 'include':
|
||||
value => $extras,
|
||||
require => File[$extras],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('--command="show max_connections" -t', 'postgres') do |r|
|
||||
expect(r.stdout).to match(/123/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
28
modules/postgresql/spec/acceptance/contrib_spec.rb
Normal file
28
modules/postgresql/spec/acceptance/contrib_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::contrib:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran, remove both contrib and server as contrib
|
||||
# pulls in the server based packages.
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server':
|
||||
ensure => absent,
|
||||
}
|
||||
class { 'postgresql::server::contrib':
|
||||
package_ensure => purged,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'test loading class with no parameters' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
class { 'postgresql::server::contrib': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
17
modules/postgresql/spec/acceptance/lib/devel_spec.rb
Normal file
17
modules/postgresql/spec/acceptance/lib/devel_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::lib::devel:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::lib::devel': package_ensure => purged }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'test loading class with no parameters' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::lib::devel': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
20
modules/postgresql/spec/acceptance/lib/java_spec.rb
Normal file
20
modules/postgresql/spec/acceptance/lib/java_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::lib::java:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::lib::java': package_ensure => purged }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'test loading class with no parameters' do
|
||||
pending('libpostgresql-java-jdbc not available natively for Ubuntu 10.04 and Debian 6',
|
||||
:if => (fact('osfamily') == 'Debian' and ['6', '10'].include?(fact('lsbmajdistrelease'))))
|
||||
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::lib::java': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
19
modules/postgresql/spec/acceptance/lib/python_spec.rb
Normal file
19
modules/postgresql/spec/acceptance/lib/python_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::lib::python:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::lib::python': package_ensure => purged }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'test loading class with no parameters' do
|
||||
pending('psycopg2 not available natively for centos 5', :if => (fact('osfamily') == 'RedHat' and fact('lsbmajdistrelease') == '5'))
|
||||
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::lib::python': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
centos-510-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: el-5-x86_64
|
||||
box : centos-510-x64-virtualbox-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-510-x64-virtualbox-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
centos-59-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: el-5-x86_64
|
||||
box : centos-59-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-59-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
|
@ -0,0 +1,12 @@
|
|||
HOSTS:
|
||||
centos-64-x64:
|
||||
roles:
|
||||
- master
|
||||
- database
|
||||
- dashboard
|
||||
platform: el-6-x86_64
|
||||
box : centos-64-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: pe
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
centos-64-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: el-6-x86_64
|
||||
box : centos-64-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
debian-607-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: debian-6-amd64
|
||||
box : debian-607-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-607-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
debian-73-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: debian-7-amd64
|
||||
box : debian-73-x64-virtualbox-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-73-x64-virtualbox-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
10
modules/postgresql/spec/acceptance/nodesets/default.yml
Normal file
10
modules/postgresql/spec/acceptance/nodesets/default.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
centos-64-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: el-6-x86_64
|
||||
box : centos-64-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
ubuntu-server-10044-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: ubuntu-10.04-amd64
|
||||
box : ubuntu-server-10044-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
ubuntu-server-12042-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: ubuntu-12.04-amd64
|
||||
box : ubuntu-server-12042-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
43
modules/postgresql/spec/acceptance/postgresql_psql_spec.rb
Normal file
43
modules/postgresql/spec/acceptance/postgresql_psql_spec.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql_psql:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should run some SQL when the unless query returns no rows' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql_psql { 'foobar':
|
||||
db => 'postgres',
|
||||
psql_user => 'postgres',
|
||||
command => 'select 1',
|
||||
unless => 'select 1 where 1=2',
|
||||
require => Class['postgresql::server'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should not run SQL when the unless query returns rows' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql_psql { 'foobar':
|
||||
db => 'postgres',
|
||||
psql_user => 'postgres',
|
||||
command => 'select * from pg_database limit 1',
|
||||
unless => 'select 1 where 1=1',
|
||||
require => Class['postgresql::server'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,26 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::config_entry:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should change setting and reflect it in show all' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::config_entry { 'check_function_bodies':
|
||||
value => 'off',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('--command="show all" postgres') do |r|
|
||||
expect(r.stdout).to match(/check_function_bodies.+off/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,48 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::database_grant:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should grant access so a user can create objects in a database' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'postgres'
|
||||
$user = 'psql_grant_tester'
|
||||
$password = 'psql_grant_pw'
|
||||
|
||||
class { 'postgresql::server': }
|
||||
|
||||
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
||||
user { $user:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
postgresql::server::role { $user:
|
||||
password_hash => postgresql_password($user, $password),
|
||||
}
|
||||
|
||||
postgresql::server::database { $db: }
|
||||
|
||||
postgresql::server::database_grant { 'grant create test':
|
||||
privilege => 'CREATE',
|
||||
db => $db,
|
||||
role => $user,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
# Check that the user can create a table in the database
|
||||
psql('--command="create table foo (foo int)" postgres', 'psql_grant_tester') do |r|
|
||||
expect(r.stdout).to match(/CREATE TABLE/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop table foo" postgres', 'psql_grant_tester')
|
||||
end
|
||||
end
|
||||
end
|
29
modules/postgresql/spec/acceptance/server/database_spec.rb
Normal file
29
modules/postgresql/spec/acceptance/server/database_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::database:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should idempotently create a db that we can connect to' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'postgresql_test_db'
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::database { $db: }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('--command="select datname from pg_database" postgresql_test_db') do |r|
|
||||
expect(r.stdout).to match(/postgresql_test_db/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop database postgresql_test_db" postgres')
|
||||
end
|
||||
end
|
||||
end
|
138
modules/postgresql/spec/acceptance/server/db_spec.rb
Normal file
138
modules/postgresql/spec/acceptance/server/db_spec.rb
Normal file
|
@ -0,0 +1,138 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::db', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should idempotently create a db that we can connect to' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'postgresql_test_db'
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::db { $db:
|
||||
user => $db,
|
||||
password => postgresql_password($db, $db),
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('--command="select datname from pg_database" postgresql_test_db') do |r|
|
||||
expect(r.stdout).to match(/postgresql_test_db/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop database postgresql_test_db" postgres')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should take a locale parameter' do
|
||||
pending('no support for locale parameter with centos 5', :if => (fact('osfamily') == 'RedHat' and fact('lsbmajdistrelease') == '5'))
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
postgresql::server::db { 'test1':
|
||||
user => 'test1',
|
||||
password => postgresql_password('test1', 'test1'),
|
||||
encoding => 'UTF8',
|
||||
locale => 'en_NG.UTF-8',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('-c "show lc_ctype" test1') do |r|
|
||||
expect(r.stdout).to match(/en_NG/)
|
||||
end
|
||||
|
||||
psql('-c "show lc_collate" test1') do |r|
|
||||
expect(r.stdout).to match(/en_NG/)
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop database test1" postgres')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should take an istemplate parameter' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'template2'
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::db { $db:
|
||||
user => $db,
|
||||
password => postgresql_password($db, $db),
|
||||
istemplate => true,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('--command="select datname from pg_database" template2') do |r|
|
||||
expect(r.stdout).to match(/template2/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop database template2" postgres', 'postgres', [1,2]) do |r|
|
||||
expect(r.stdout).to eq('')
|
||||
expect(r.stderr).to match(/cannot drop a template database/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'should update istemplate parameter' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'template2'
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::db { $db:
|
||||
user => $db,
|
||||
password => postgresql_password($db, $db),
|
||||
istemplate => false,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('--command="select datname from pg_database" template2') do |r|
|
||||
expect(r.stdout).to match(/template2/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop database template2" postgres')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should take a template parameter' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'postgresql_test_db'
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::db { $db:
|
||||
user => $db,
|
||||
template => 'template1',
|
||||
password => postgresql_password($db, $db),
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('--command="select datname from pg_database" postgresql_test_db') do |r|
|
||||
expect(r.stdout).to match(/postgresql_test_db/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop database postgresql_test_db" postgres')
|
||||
end
|
||||
end
|
||||
end
|
49
modules/postgresql/spec/acceptance/server/grant_spec.rb
Normal file
49
modules/postgresql/spec/acceptance/server/grant_spec.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::grant:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should grant access so a user can create in a database' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'postgres'
|
||||
$user = 'psql_grant_tester'
|
||||
$password = 'psql_grant_pw'
|
||||
|
||||
class { 'postgresql::server': }
|
||||
|
||||
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
||||
user { $user:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
postgresql::server::role { $user:
|
||||
password_hash => postgresql_password($user, $password),
|
||||
}
|
||||
|
||||
postgresql::server::database { $db: }
|
||||
|
||||
postgresql::server::grant { 'grant create test':
|
||||
object_type => 'database',
|
||||
privilege => 'CREATE',
|
||||
db => $db,
|
||||
role => $user,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
# Check that the user can create a table in the database
|
||||
psql('--command="create table foo (foo int)" postgres', 'psql_grant_tester') do |r|
|
||||
expect(r.stdout).to match(/CREATE TABLE/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop table foo" postgres', 'psql_grant_tester')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,72 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::pg_hba_rule:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should create a ruleset in pg_hba.conf' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
postgresql::server::pg_hba_rule { "allow application network to access app database":
|
||||
type => "host",
|
||||
database => "app",
|
||||
user => "app",
|
||||
address => "200.1.2.0/24",
|
||||
auth_method => md5,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
|
||||
shell("grep '200.1.2.0/24' /etc/postgresql/*/*/pg_hba.conf || grep '200.1.2.0/24' /var/lib/pgsql/data/pg_hba.conf")
|
||||
end
|
||||
|
||||
it 'should create a ruleset in pg_hba.conf that denies db access to db test1' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::db { "test1":
|
||||
user => "test1",
|
||||
password => postgresql_password('test1', 'test1'),
|
||||
grant => "all",
|
||||
}
|
||||
|
||||
postgresql::server::pg_hba_rule { "allow anyone to have access to db test1":
|
||||
type => "local",
|
||||
database => "test1",
|
||||
user => "test1",
|
||||
auth_method => reject,
|
||||
order => '001',
|
||||
}
|
||||
|
||||
user { "test1":
|
||||
shell => "/bin/bash",
|
||||
managehome => true,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
|
||||
shell('su - test1 -c \'psql -U test1 -c "\q" test1\'', :acceptable_exit_codes => [2])
|
||||
end
|
||||
|
||||
it 'should fail catalogue if postgresql::server::manage_pga_conf is disabled' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server':
|
||||
manage_pg_hba_conf => false,
|
||||
}
|
||||
postgresql::server::pg_hba_rule { 'foo':
|
||||
type => "local",
|
||||
database => "test1",
|
||||
user => "test1",
|
||||
auth_method => reject,
|
||||
order => '001',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :expect_failures => true)
|
||||
end
|
||||
end
|
25
modules/postgresql/spec/acceptance/server/plperl_spec.rb
Normal file
25
modules/postgresql/spec/acceptance/server/plperl_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'server plperl:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': ensure => absent }
|
||||
class { 'postgresql::server::plperl': package_ensure => purged }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'test loading class with no parameters' do
|
||||
pending('no support for plperl with default version on centos 5',
|
||||
:if => (fact('osfamily') == 'RedHat' and fact('lsbmajdistrelease') == '5'))
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
class { 'postgresql::server::plperl': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
88
modules/postgresql/spec/acceptance/server/role_spec.rb
Normal file
88
modules/postgresql/spec/acceptance/server/role_spec.rb
Normal file
|
@ -0,0 +1,88 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::role:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should idempotently create a user who can log in' do
|
||||
pp = <<-EOS.unindent
|
||||
$user = "postgresql_test_user"
|
||||
$password = "postgresql_test_password"
|
||||
|
||||
class { 'postgresql::server': }
|
||||
|
||||
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
||||
user { $user:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
postgresql::server::role { $user:
|
||||
password_hash => postgresql_password($user, $password),
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
|
||||
# Check that the user can log in
|
||||
psql('--command="select datname from pg_database" postgres', 'postgresql_test_user') do |r|
|
||||
expect(r.stdout).to match(/template1/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should idempotently alter a user who can log in' do
|
||||
pp = <<-EOS.unindent
|
||||
$user = "postgresql_test_user"
|
||||
$password = "postgresql_test_password2"
|
||||
|
||||
class { 'postgresql::server': }
|
||||
|
||||
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
||||
user { $user:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
postgresql::server::role { $user:
|
||||
password_hash => postgresql_password($user, $password),
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
# Check that the user can log in
|
||||
psql('--command="select datname from pg_database" postgres', 'postgresql_test_user') do |r|
|
||||
expect(r.stdout).to match(/template1/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should idempotently create a user with a cleartext password' do
|
||||
pp = <<-EOS.unindent
|
||||
$user = "postgresql_test_user2"
|
||||
$password = "postgresql_test_password2"
|
||||
|
||||
class { 'postgresql::server': }
|
||||
|
||||
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
||||
user { $user:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
postgresql::server::role { $user:
|
||||
password_hash => $password,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
# Check that the user can log in
|
||||
psql('--command="select datname from pg_database" postgres', 'postgresql_test_user2') do |r|
|
||||
expect(r.stdout).to match(/template1/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
end
|
||||
end
|
124
modules/postgresql/spec/acceptance/server/table_grant_spec.rb
Normal file
124
modules/postgresql/spec/acceptance/server/table_grant_spec.rb
Normal file
|
@ -0,0 +1,124 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::table_grant:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should grant all accesses to a user' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'table_grant'
|
||||
$user = 'psql_grant_tester'
|
||||
$password = 'psql_table_pw'
|
||||
|
||||
class { 'postgresql::server': }
|
||||
|
||||
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
||||
user { $user:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
postgresql::server::role { $user:
|
||||
password_hash => postgresql_password($user, $password),
|
||||
}
|
||||
|
||||
postgresql::server::database { $db: }
|
||||
|
||||
# Create a rule for the user
|
||||
postgresql::server::pg_hba_rule { "allow ${user}":
|
||||
type => 'local',
|
||||
database => $db,
|
||||
user => $user,
|
||||
auth_method => 'ident',
|
||||
order => 1,
|
||||
}
|
||||
|
||||
postgresql_psql { 'Create testing table':
|
||||
command => 'CREATE TABLE "test_table" (field integer NOT NULL)',
|
||||
db => $db,
|
||||
unless => "SELECT * FROM pg_tables WHERE tablename = 'test_table'",
|
||||
require => Postgresql::Server::Database[$db],
|
||||
}
|
||||
|
||||
postgresql::server::table_grant { 'grant insert test':
|
||||
privilege => 'ALL',
|
||||
table => 'test_table',
|
||||
db => $db,
|
||||
role => $user,
|
||||
require => Postgresql_psql['Create testing table'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
## Check that the user can create a table in the database
|
||||
psql('--command="create table foo (foo int)" postgres', 'psql_grant_tester') do |r|
|
||||
expect(r.stdout).to match(/CREATE TABLE/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop table foo" postgres', 'psql_grant_tester')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should grant access so a user can insert in a table' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'table_grant'
|
||||
$user = 'psql_grant_tester'
|
||||
$password = 'psql_table_pw'
|
||||
|
||||
class { 'postgresql::server': }
|
||||
|
||||
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
||||
user { $user:
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
postgresql::server::role { $user:
|
||||
password_hash => postgresql_password($user, $password),
|
||||
}
|
||||
|
||||
postgresql::server::database { $db: }
|
||||
|
||||
# Create a rule for the user
|
||||
postgresql::server::pg_hba_rule { "allow ${user}":
|
||||
type => 'local',
|
||||
database => $db,
|
||||
user => $user,
|
||||
auth_method => 'ident',
|
||||
order => 1,
|
||||
}
|
||||
|
||||
postgresql_psql { 'Create testing table':
|
||||
command => 'CREATE TABLE "test_table" (field integer NOT NULL)',
|
||||
db => $db,
|
||||
unless => "SELECT * FROM pg_tables WHERE tablename = 'test_table'",
|
||||
require => Postgresql::Server::Database[$db],
|
||||
}
|
||||
|
||||
postgresql::server::table_grant { 'grant insert test':
|
||||
privilege => 'INSERT',
|
||||
table => 'test_table',
|
||||
db => $db,
|
||||
role => $user,
|
||||
require => Postgresql_psql['Create testing table'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
## Check that the user can create a table in the database
|
||||
psql('--command="create table foo (foo int)" postgres', 'psql_grant_tester') do |r|
|
||||
expect(r.stdout).to match(/CREATE TABLE/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop table foo" postgres', 'psql_grant_tester')
|
||||
end
|
||||
end
|
||||
end
|
67
modules/postgresql/spec/acceptance/server/tablespace_spec.rb
Normal file
67
modules/postgresql/spec/acceptance/server/tablespace_spec.rb
Normal file
|
@ -0,0 +1,67 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::tablespace:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should idempotently create tablespaces and databases that are using them' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
file { '/tmp/postgres/pg_tablespaces':
|
||||
ensure => 'directory',
|
||||
owner => 'postgres',
|
||||
group => 'postgres',
|
||||
mode => '0700',
|
||||
}
|
||||
|
||||
postgresql::server::tablespace { 'tablespace1':
|
||||
location => '/tmp/postgres/pg_tablespaces/space1',
|
||||
}
|
||||
postgresql::server::database { 'tablespacedb1':
|
||||
encoding => 'utf8',
|
||||
tablespace => 'tablespace1',
|
||||
}
|
||||
postgresql::server::db { 'tablespacedb2':
|
||||
user => 'dbuser2',
|
||||
password => postgresql_password('dbuser2', 'dbuser2'),
|
||||
tablespace => 'tablespace1',
|
||||
}
|
||||
|
||||
postgresql::server::role { 'spcuser':
|
||||
password_hash => postgresql_password('spcuser', 'spcuser'),
|
||||
}
|
||||
postgresql::server::tablespace { 'tablespace2':
|
||||
location => '/tmp/postgres/pg_tablespaces/space2',
|
||||
owner => 'spcuser',
|
||||
}
|
||||
postgresql::server::database { 'tablespacedb3':
|
||||
encoding => 'utf8',
|
||||
tablespace => 'tablespace2',
|
||||
}
|
||||
EOS
|
||||
|
||||
shell('mkdir -p /tmp/postgres')
|
||||
# Apply appropriate selinux labels
|
||||
if fact('osfamily') == 'RedHat'
|
||||
if shell('getenforce').stdout =~ /Enforcing/
|
||||
shell('chcon -Rv --type=postgresql_db_t /tmp/postgres')
|
||||
end
|
||||
end
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
# Check that databases use correct tablespaces
|
||||
psql('--command="select ts.spcname from pg_database db, pg_tablespace ts where db.dattablespace = ts.oid and db.datname = \'"\'tablespacedb1\'"\'"') do |r|
|
||||
expect(r.stdout).to match(/tablespace1/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
|
||||
psql('--command="select ts.spcname from pg_database db, pg_tablespace ts where db.dattablespace = ts.oid and db.datname = \'"\'tablespacedb3\'"\'"') do |r|
|
||||
expect(r.stdout).to match(/tablespace2/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
end
|
||||
end
|
188
modules/postgresql/spec/acceptance/server_spec.rb
Normal file
188
modules/postgresql/spec/acceptance/server_spec.rb
Normal file
|
@ -0,0 +1,188 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'server:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'test loading class with no parameters' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
describe port(5432) do
|
||||
it { should be_listening }
|
||||
end
|
||||
|
||||
describe 'setting postgres password' do
|
||||
it 'should install and successfully adjust the password' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server':
|
||||
postgres_password => 'foobarbaz',
|
||||
ip_mask_deny_postgres_user => '0.0.0.0/32',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/\[set_postgres_postgrespw\]\/returns: executed successfully/)
|
||||
end
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server':
|
||||
postgres_password => 'TPSR$$eports!',
|
||||
ip_mask_deny_postgres_user => '0.0.0.0/32',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/\[set_postgres_postgrespw\]\/returns: executed successfully/)
|
||||
end
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'server without defaults:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
context 'test installing non-default version of postgresql' do
|
||||
after :all do
|
||||
psql('--command="drop database postgresql_test_db" postgres', 'postgres')
|
||||
pp = <<-EOS.unindent
|
||||
if $::osfamily == 'Debian' {
|
||||
class { 'apt': }
|
||||
# XXX Need to purge postgresql-common after uninstalling 9.3 because
|
||||
# it leaves the init script behind. Poor packaging.
|
||||
package { 'postgresql-common':
|
||||
ensure => purged,
|
||||
require => Class['postgresql::server'],
|
||||
}
|
||||
}
|
||||
class { 'postgresql::globals':
|
||||
ensure => absent,
|
||||
manage_package_repo => true,
|
||||
version => '9.3',
|
||||
}
|
||||
class { 'postgresql::server':
|
||||
ensure => absent,
|
||||
}
|
||||
EOS
|
||||
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq('')
|
||||
end
|
||||
|
||||
it 'perform installation and create a db' do
|
||||
pp = <<-EOS.unindent
|
||||
if $::osfamily == 'Debian' {
|
||||
class { 'apt': }
|
||||
}
|
||||
class { "postgresql::globals":
|
||||
version => "9.3",
|
||||
manage_package_repo => true,
|
||||
encoding => 'UTF8',
|
||||
locale => 'en_US.UTF-8',
|
||||
xlogdir => '/tmp/pg_xlogs',
|
||||
}
|
||||
class { "postgresql::server": }
|
||||
postgresql::server::db { "postgresql_test_db":
|
||||
user => "foo1",
|
||||
password => postgresql_password('foo1', 'foo1'),
|
||||
}
|
||||
postgresql::server::config_entry { 'port':
|
||||
value => '5432',
|
||||
}
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :catch_failures => true).stderr).to eq('')
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
shell('test -d /tmp/pg_xlogs') do |r|
|
||||
expect(r.stdout).to eq('')
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
|
||||
psql('postgresql_test_db --command="select datname from pg_database limit 1"')
|
||||
end
|
||||
|
||||
describe port(5432) do
|
||||
it { should be_listening }
|
||||
end
|
||||
end
|
||||
|
||||
unless ((fact('osfamily') == 'RedHat' and fact('lsbmajdistrelease') == '5') ||
|
||||
fact('osfamily') == 'Debian')
|
||||
|
||||
context 'override locale and encoding' do
|
||||
after :each do
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'perform installation with different locale and encoding' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server':
|
||||
locale => 'en_NG',
|
||||
encoding => 'UTF8',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
# Remove db first, if it exists for some reason
|
||||
shell('su postgres -c "dropdb test1"', :acceptable_exit_codes => [0,1,2])
|
||||
shell('su postgres -c "createdb test1"')
|
||||
shell('su postgres -c \'psql -c "show lc_ctype" test1\'') do |r|
|
||||
expect(r.stdout).to match(/en_NG/)
|
||||
end
|
||||
|
||||
shell('su postgres -c \'psql -c "show lc_collate" test1\'') do |r|
|
||||
expect(r.stdout).to match(/en_NG/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'server with firewall:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
context 'test installing postgresql with firewall management on' do
|
||||
it 'perform installation and make sure it is idempotent' do
|
||||
pending('no support for firewall with fedora', :if => (fact('operatingsystem') == 'Fedora'))
|
||||
pp = <<-EOS.unindent
|
||||
class { 'firewall': }
|
||||
class { "postgresql::server":
|
||||
manage_firewall => true,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'server without pg_hba.conf:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
context 'test installing postgresql without pg_hba.conf management on' do
|
||||
it 'perform installation and make sure it is idempotent' do
|
||||
pp = <<-EOS.unindent
|
||||
class { "postgresql::server":
|
||||
manage_pg_hba_conf => false,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
||||
end
|
16
modules/postgresql/spec/acceptance/unsupported_spec.rb
Normal file
16
modules/postgresql/spec/acceptance/unsupported_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'unsupported distributions and OSes', :if => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
it 'should fail for client' do
|
||||
pp = <<-EOS
|
||||
class { 'postgresql::client': }
|
||||
EOS
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/does not provide defaults for osfamily/i)
|
||||
end
|
||||
it 'should fail for server' do
|
||||
pp = <<-EOS
|
||||
class { 'postgresql::server': }
|
||||
EOS
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/does not provide defaults for osfamily/i)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,79 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::validate_db_connection:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
before :all do
|
||||
# Setup postgresql server and a sample database for tests to use.
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'foo'
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::db { $db:
|
||||
user => $db,
|
||||
password => postgresql_password($db, $db),
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
after :all do
|
||||
# Remove postgresql server after all tests have ran.
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should run puppet with no changes declared if socket connectivity works' do
|
||||
pp = <<-EOS.unindent
|
||||
postgresql::validate_db_connection { 'foo':
|
||||
database_name => 'foo',
|
||||
run_as => 'postgres',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should keep retrying if database is down' do
|
||||
# So first we shut the db down, then background a startup routine with a
|
||||
# sleep 10 in front of it. That way the tests should continue while
|
||||
# the pause and db startup happens in the background.
|
||||
shell("/etc/init.d/postgresql* stop")
|
||||
shell('nohup bash -c "sleep 10; /etc/init.d/postgresql* start" > /dev/null 2>&1 &')
|
||||
|
||||
pp = <<-EOS.unindent
|
||||
postgresql::validate_db_connection { 'foo':
|
||||
database_name => 'foo',
|
||||
tries => 30,
|
||||
sleep => 1,
|
||||
run_as => 'postgres',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should run puppet with no changes declared if db ip connectivity works' do
|
||||
pp = <<-EOS.unindent
|
||||
postgresql::validate_db_connection { 'foo':
|
||||
database_host => 'localhost',
|
||||
database_name => 'foo',
|
||||
database_username => 'foo',
|
||||
database_password => 'foo',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should fail catalogue if database connectivity fails' do
|
||||
pp = <<-EOS.unindent
|
||||
postgresql::validate_db_connection { 'foobarbaz':
|
||||
database_host => 'localhost',
|
||||
database_name => 'foobarbaz',
|
||||
database_username => 'foobarbaz',
|
||||
database_password => 'foobarbaz',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :expect_failures => true)
|
||||
end
|
||||
end
|
30
modules/postgresql/spec/spec_helper.rb
Normal file
30
modules/postgresql/spec/spec_helper.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require 'puppetlabs_spec_helper/module_spec_helper'
|
||||
|
||||
RSpec.configure do |c|
|
||||
c.mock_with :rspec do |mock|
|
||||
mock.syntax = [:expect, :should]
|
||||
end
|
||||
c.include PuppetlabsSpec::Files
|
||||
|
||||
c.before :each do
|
||||
# Ensure that we don't accidentally cache facts and environment
|
||||
# between test cases.
|
||||
Facter::Util::Loader.any_instance.stubs(:load_all)
|
||||
Facter.clear
|
||||
Facter.clear_messages
|
||||
|
||||
# Store any environment variables away to be restored later
|
||||
@old_env = {}
|
||||
ENV.each_key {|k| @old_env[k] = ENV[k]}
|
||||
end
|
||||
|
||||
c.after :each do
|
||||
PuppetlabsSpec::Files.cleanup
|
||||
end
|
||||
end
|
||||
|
||||
# Convenience helper for returning parameters for a type from the
|
||||
# catalogue.
|
||||
def param(type, title, param)
|
||||
param_value(catalogue, type, title, param)
|
||||
end
|
75
modules/postgresql/spec/spec_helper_acceptance.rb
Normal file
75
modules/postgresql/spec/spec_helper_acceptance.rb
Normal file
|
@ -0,0 +1,75 @@
|
|||
require 'beaker-rspec/spec_helper'
|
||||
require 'beaker-rspec/helpers/serverspec'
|
||||
|
||||
class String
|
||||
# Provide ability to remove indentation from strings, for the purpose of
|
||||
# left justifying heredoc blocks.
|
||||
def unindent
|
||||
gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "")
|
||||
end
|
||||
end
|
||||
|
||||
def shellescape(str)
|
||||
str = str.to_s
|
||||
|
||||
# An empty argument will be skipped, so return empty quotes.
|
||||
return "''" if str.empty?
|
||||
|
||||
str = str.dup
|
||||
|
||||
# Treat multibyte characters as is. It is caller's responsibility
|
||||
# to encode the string in the right encoding for the shell
|
||||
# environment.
|
||||
str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\\\1")
|
||||
|
||||
# A LF cannot be escaped with a backslash because a backslash + LF
|
||||
# combo is regarded as line continuation and simply ignored.
|
||||
str.gsub!(/\n/, "'\n'")
|
||||
|
||||
return str
|
||||
end
|
||||
|
||||
def psql(psql_cmd, user = 'postgres', exit_codes = [0], &block)
|
||||
psql = "psql #{psql_cmd}"
|
||||
shell("su #{shellescape(user)} -c #{shellescape(psql)}", :acceptable_exit_codes => exit_codes, &block)
|
||||
end
|
||||
|
||||
unless ENV['RS_PROVISION'] == 'no'
|
||||
hosts.each do |host|
|
||||
if host.is_pe?
|
||||
install_pe
|
||||
else
|
||||
install_puppet
|
||||
on host, "mkdir -p #{host['distmoduledir']}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
UNSUPPORTED_PLATFORMS = ['AIX','windows','Solaris','Suse']
|
||||
|
||||
RSpec.configure do |c|
|
||||
# Project root
|
||||
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
||||
|
||||
# Readable test descriptions
|
||||
c.formatter = :documentation
|
||||
|
||||
# Configure all nodes in nodeset
|
||||
c.before :suite do
|
||||
# Install module and dependencies
|
||||
puppet_module_install(:source => proj_root, :module_name => 'postgresql')
|
||||
hosts.each do |host|
|
||||
on host, "/bin/touch #{default['puppetpath']}/hiera.yaml"
|
||||
on host, 'chmod 755 /root'
|
||||
if fact('osfamily') == 'Debian'
|
||||
on host, "echo \"en_US ISO-8859-1\nen_NG.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\n\" > /etc/locale.gen"
|
||||
on host, '/usr/sbin/locale-gen'
|
||||
on host, '/usr/sbin/update-locale'
|
||||
end
|
||||
on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] }
|
||||
on host, puppet('module','install','puppetlabs-firewall'), { :acceptable_exit_codes => [0,1] }
|
||||
on host, puppet('module','install','puppetlabs-apt'), { :acceptable_exit_codes => [0,1] }
|
||||
on host, puppet('module','install','puppetlabs-concat'), { :acceptable_exit_codes => [0,1] }
|
||||
end
|
||||
end
|
||||
end
|
36
modules/postgresql/spec/unit/classes/client_spec.rb
Normal file
36
modules/postgresql/spec/unit/classes/client_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::client', :type => :class do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
|
||||
describe 'with parameters' do
|
||||
let :params do
|
||||
{
|
||||
:package_ensure => 'absent',
|
||||
:package_name => 'mypackage',
|
||||
}
|
||||
end
|
||||
|
||||
it 'should modify package' do
|
||||
should contain_package("postgresql-client").with({
|
||||
:ensure => 'absent',
|
||||
:name => 'mypackage',
|
||||
:tag => 'postgresql',
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with no parameters' do
|
||||
it 'should create package with postgresql tag' do
|
||||
should contain_package('postgresql-client').with({
|
||||
:tag => 'postgresql',
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
29
modules/postgresql/spec/unit/classes/globals_spec.rb
Normal file
29
modules/postgresql/spec/unit/classes/globals_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::globals', :type => :class do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
:lsbdistid => 'Debian',
|
||||
}
|
||||
end
|
||||
|
||||
describe 'with no parameters' do
|
||||
it 'should work' do
|
||||
should contain_class("postgresql::globals")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'manage_package_repo => true' do
|
||||
let(:params) do
|
||||
{
|
||||
:manage_package_repo => true,
|
||||
}
|
||||
end
|
||||
it 'should pull in class postgresql::repo' do
|
||||
should contain_class("postgresql::repo")
|
||||
end
|
||||
end
|
||||
end
|
12
modules/postgresql/spec/unit/classes/lib/devel_spec.rb
Normal file
12
modules/postgresql/spec/unit/classes/lib/devel_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::lib::devel', :type => :class do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
it { should contain_class("postgresql::lib::devel") }
|
||||
end
|
40
modules/postgresql/spec/unit/classes/lib/java_spec.rb
Normal file
40
modules/postgresql/spec/unit/classes/lib/java_spec.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::lib::java', :type => :class do
|
||||
|
||||
describe 'on a debian based os' do
|
||||
let :facts do {
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
it { should contain_package('postgresql-jdbc').with(
|
||||
:name => 'libpostgresql-jdbc-java',
|
||||
:ensure => 'present'
|
||||
)}
|
||||
end
|
||||
|
||||
describe 'on a redhat based os' do
|
||||
let :facts do {
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'RedHat',
|
||||
:operatingsystemrelease => '6.4',
|
||||
}
|
||||
end
|
||||
it { should contain_package('postgresql-jdbc').with(
|
||||
:name => 'postgresql-jdbc',
|
||||
:ensure => 'present'
|
||||
)}
|
||||
describe 'when parameters are supplied' do
|
||||
let :params do
|
||||
{:package_ensure => 'latest', :package_name => 'somepackage'}
|
||||
end
|
||||
it { should contain_package('postgresql-jdbc').with(
|
||||
:name => 'somepackage',
|
||||
:ensure => 'latest'
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
31
modules/postgresql/spec/unit/classes/lib/python_spec.rb
Normal file
31
modules/postgresql/spec/unit/classes/lib/python_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::lib::python', :type => :class do
|
||||
|
||||
describe 'on a redhat based os' do
|
||||
let :facts do {
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'RedHat',
|
||||
:operatingsystemrelease => '6.4',
|
||||
}
|
||||
end
|
||||
it { should contain_package('python-psycopg2').with(
|
||||
:name => 'python-psycopg2',
|
||||
:ensure => 'present'
|
||||
)}
|
||||
end
|
||||
|
||||
describe 'on a debian based os' do
|
||||
let :facts do {
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
it { should contain_package('python-psycopg2').with(
|
||||
:name => 'python-psycopg2',
|
||||
:ensure => 'present'
|
||||
)}
|
||||
end
|
||||
|
||||
end
|
12
modules/postgresql/spec/unit/classes/params_spec.rb
Normal file
12
modules/postgresql/spec/unit/classes/params_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::params', :type => :class do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
it { should contain_class("postgresql::params") }
|
||||
end
|
18
modules/postgresql/spec/unit/classes/repo_spec.rb
Normal file
18
modules/postgresql/spec/unit/classes/repo_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::repo', :type => :class do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
:lsbdistid => 'Debian',
|
||||
}
|
||||
end
|
||||
|
||||
describe 'with no parameters' do
|
||||
it 'should instantiate apt_postgresql_org class' do
|
||||
should contain_class('postgresql::repo::apt_postgresql_org')
|
||||
end
|
||||
end
|
||||
end
|
42
modules/postgresql/spec/unit/classes/server/contrib_spec.rb
Normal file
42
modules/postgresql/spec/unit/classes/server/contrib_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::server::contrib', :type => :class do
|
||||
let :pre_condition do
|
||||
"class { 'postgresql::server': }"
|
||||
end
|
||||
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
:kernel => 'Linux',
|
||||
:concat_basedir => tmpfilename('contrib'),
|
||||
}
|
||||
end
|
||||
|
||||
describe 'with parameters' do
|
||||
let(:params) do
|
||||
{
|
||||
:package_name => 'mypackage',
|
||||
:package_ensure => 'absent',
|
||||
}
|
||||
end
|
||||
|
||||
it 'should create package with correct params' do
|
||||
should contain_package('postgresql-contrib').with({
|
||||
:ensure => 'absent',
|
||||
:name => 'mypackage',
|
||||
:tag => 'postgresql',
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with no parameters' do
|
||||
it 'should create package with postgresql tag' do
|
||||
should contain_package('postgresql-contrib').with({
|
||||
:tag => 'postgresql',
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
29
modules/postgresql/spec/unit/classes/server/initdb_spec.rb
Normal file
29
modules/postgresql/spec/unit/classes/server/initdb_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::server::initdb', :type => :class do
|
||||
let (:pre_condition) do
|
||||
"include postgresql::server"
|
||||
end
|
||||
describe 'on RedHat' do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'CentOS',
|
||||
:operatingsystemrelease => '6.0',
|
||||
:concat_basedir => tmpfilename('server'),
|
||||
}
|
||||
end
|
||||
it { should contain_file('/var/lib/pgsql/data').with_ensure('directory') }
|
||||
end
|
||||
describe 'on Amazon' do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'Amazon',
|
||||
:concat_basedir => tmpfilename('server'),
|
||||
}
|
||||
end
|
||||
it { should contain_file('/var/lib/pgsql9/data').with_ensure('directory') }
|
||||
end
|
||||
end
|
||||
|
45
modules/postgresql/spec/unit/classes/server/plperl_spec.rb
Normal file
45
modules/postgresql/spec/unit/classes/server/plperl_spec.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::server::plperl', :type => :class do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
:kernel => 'Linux',
|
||||
:concat_basedir => tmpfilename('plperl'),
|
||||
}
|
||||
end
|
||||
|
||||
let :pre_condition do
|
||||
"class { 'postgresql::server': }"
|
||||
end
|
||||
|
||||
describe 'with no parameters' do
|
||||
it { should contain_class("postgresql::server::plperl") }
|
||||
it 'should create package' do
|
||||
should contain_package('postgresql-plperl').with({
|
||||
:ensure => 'present',
|
||||
:tag => 'postgresql',
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with parameters' do
|
||||
let :params do
|
||||
{
|
||||
:package_ensure => 'absent',
|
||||
:package_name => 'mypackage',
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_class("postgresql::server::plperl") }
|
||||
it 'should create package with correct params' do
|
||||
should contain_package('postgresql-plperl').with({
|
||||
:ensure => 'absent',
|
||||
:name => 'mypackage',
|
||||
:tag => 'postgresql',
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
100
modules/postgresql/spec/unit/classes/server_spec.rb
Normal file
100
modules/postgresql/spec/unit/classes/server_spec.rb
Normal file
|
@ -0,0 +1,100 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::server', :type => :class do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
:concat_basedir => tmpfilename('server'),
|
||||
:kernel => 'Linux',
|
||||
}
|
||||
end
|
||||
|
||||
describe 'with no parameters' do
|
||||
it { should contain_class("postgresql::params") }
|
||||
it { should contain_class("postgresql::server") }
|
||||
it 'should validate connection' do
|
||||
should contain_postgresql__validate_db_connection('validate_service_is_running')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'manage_firewall => true' do
|
||||
let(:params) do
|
||||
{
|
||||
:manage_firewall => true,
|
||||
:ensure => true,
|
||||
}
|
||||
end
|
||||
|
||||
it 'should create firewall rule' do
|
||||
should contain_firewall("5432 accept - postgres")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'ensure => absent' do
|
||||
let(:params) do
|
||||
{
|
||||
:ensure => 'absent',
|
||||
:datadir => '/my/path',
|
||||
:xlogdir => '/xlog/path',
|
||||
}
|
||||
end
|
||||
|
||||
it 'should make package purged' do
|
||||
should contain_package('postgresql-server').with({
|
||||
:ensure => 'purged',
|
||||
})
|
||||
end
|
||||
|
||||
it 'stop the service' do
|
||||
should contain_service('postgresqld').with({
|
||||
:ensure => false,
|
||||
})
|
||||
end
|
||||
|
||||
it 'should remove datadir' do
|
||||
should contain_file('/my/path').with({
|
||||
:ensure => 'absent',
|
||||
})
|
||||
end
|
||||
|
||||
it 'should remove xlogdir' do
|
||||
should contain_file('/xlog/path').with({
|
||||
:ensure => 'absent',
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe 'package_ensure => absent' do
|
||||
let(:params) do
|
||||
{
|
||||
:package_ensure => 'absent',
|
||||
}
|
||||
end
|
||||
|
||||
it 'should remove the package' do
|
||||
should contain_package('postgresql-server').with({
|
||||
:ensure => 'purged',
|
||||
})
|
||||
end
|
||||
|
||||
it 'should still enable the service' do
|
||||
should contain_service('postgresqld').with({
|
||||
:ensure => true,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe 'needs_initdb => true' do
|
||||
let(:params) do
|
||||
{
|
||||
:needs_initdb => true,
|
||||
}
|
||||
end
|
||||
|
||||
it 'should contain proper initdb exec' do
|
||||
should contain_exec('postgresql_initdb')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,23 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::server::config_entry', :type => :define do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'RedHat',
|
||||
:operatingsystemrelease => '6.4',
|
||||
}
|
||||
end
|
||||
|
||||
let(:title) { 'config_entry'}
|
||||
|
||||
let :target do
|
||||
tmpfilename('postgresql_conf')
|
||||
end
|
||||
|
||||
context "syntax check" do
|
||||
let(:params) { { :ensure => 'present'} }
|
||||
it { should contain_postgresql__server__config_entry('config_entry') }
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::server::database_grant', :type => :define do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
|
||||
let :title do
|
||||
'test'
|
||||
end
|
||||
|
||||
let :params do
|
||||
{
|
||||
:privilege => 'ALL',
|
||||
:db => 'test',
|
||||
:role => 'test',
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_postgresql__server__database_grant('test') }
|
||||
it { should contain_postgresql__server__grant('database:test') }
|
||||
end
|
16
modules/postgresql/spec/unit/defines/server/database_spec.rb
Normal file
16
modules/postgresql/spec/unit/defines/server/database_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::server::database', :type => :define do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
let :title do
|
||||
'test'
|
||||
end
|
||||
it { should contain_postgresql__server__database('test') }
|
||||
it { should contain_postgresql_psql("Check for existence of db 'test'") }
|
||||
end
|
28
modules/postgresql/spec/unit/defines/server/db_spec.rb
Normal file
28
modules/postgresql/spec/unit/defines/server/db_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::server::db', :type => :define do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
|
||||
let :title do
|
||||
'test'
|
||||
end
|
||||
|
||||
let :params do
|
||||
{
|
||||
:user => 'test',
|
||||
:password => 'test',
|
||||
:owner => 'tester',
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_postgresql__server__db('test') }
|
||||
it { should contain_postgresql__server__database('test').with_owner('tester') }
|
||||
it { should contain_postgresql__server__role('test') }
|
||||
it { should contain_postgresql__server__database_grant('GRANT test - ALL - test') }
|
||||
end
|
24
modules/postgresql/spec/unit/defines/server/grant_spec.rb
Normal file
24
modules/postgresql/spec/unit/defines/server/grant_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::server::grant', :type => :define do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
|
||||
let :title do
|
||||
'test'
|
||||
end
|
||||
|
||||
let :params do
|
||||
{
|
||||
:db => 'test',
|
||||
:role => 'test',
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_postgresql__server__grant('test') }
|
||||
end
|
161
modules/postgresql/spec/unit/defines/server/pg_hba_rule_spec.rb
Normal file
161
modules/postgresql/spec/unit/defines/server/pg_hba_rule_spec.rb
Normal file
|
@ -0,0 +1,161 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::server::pg_hba_rule', :type => :define do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
:concat_basedir => tmpfilename('pg_hba'),
|
||||
}
|
||||
end
|
||||
let :title do
|
||||
'test'
|
||||
end
|
||||
let :target do
|
||||
tmpfilename('pg_hba_rule')
|
||||
end
|
||||
|
||||
context 'test template 1' do
|
||||
let :params do
|
||||
{
|
||||
:type => 'host',
|
||||
:database => 'all',
|
||||
:user => 'all',
|
||||
:address => '1.1.1.1/24',
|
||||
:auth_method => 'md5',
|
||||
:target => target,
|
||||
}
|
||||
end
|
||||
it do
|
||||
content = param('concat::fragment', 'pg_hba_rule_test', 'content')
|
||||
content.should =~ /host\s+all\s+all\s+1\.1\.1\.1\/24\s+md5/
|
||||
end
|
||||
end
|
||||
|
||||
context 'test template 2' do
|
||||
let :params do
|
||||
{
|
||||
:type => 'local',
|
||||
:database => 'all',
|
||||
:user => 'all',
|
||||
:auth_method => 'ident',
|
||||
:target => target,
|
||||
}
|
||||
end
|
||||
it do
|
||||
content = param('concat::fragment', 'pg_hba_rule_test', 'content')
|
||||
content.should =~ /local\s+all\s+all\s+ident/
|
||||
end
|
||||
end
|
||||
|
||||
context 'test template 3' do
|
||||
let :params do
|
||||
{
|
||||
:type => 'host',
|
||||
:database => 'all',
|
||||
:user => 'all',
|
||||
:address => '0.0.0.0/0',
|
||||
:auth_method => 'ldap',
|
||||
:auth_option => 'foo=bar',
|
||||
:target => target,
|
||||
}
|
||||
end
|
||||
it do
|
||||
content = param('concat::fragment', 'pg_hba_rule_test', 'content')
|
||||
content.should =~ /host\s+all\s+all\s+0\.0\.0\.0\/0\s+ldap\s+foo=bar/
|
||||
end
|
||||
end
|
||||
|
||||
context 'validation' do
|
||||
context 'validate type test 1' do
|
||||
let :params do
|
||||
{
|
||||
:type => 'invalid',
|
||||
:database => 'all',
|
||||
:user => 'all',
|
||||
:address => '0.0.0.0/0',
|
||||
:auth_method => 'ldap',
|
||||
:target => target,
|
||||
}
|
||||
end
|
||||
it 'should fail parsing when type is not valid' do
|
||||
expect {subject}.to raise_error(Puppet::Error,
|
||||
/The type you specified \[invalid\] must be one of/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'validate auth_method' do
|
||||
let :params do
|
||||
{
|
||||
:type => 'local',
|
||||
:database => 'all',
|
||||
:user => 'all',
|
||||
:address => '0.0.0.0/0',
|
||||
:auth_method => 'invalid',
|
||||
:target => target,
|
||||
}
|
||||
end
|
||||
|
||||
it 'should fail parsing when auth_method is not valid' do
|
||||
expect {subject}.to raise_error(Puppet::Error,
|
||||
/The auth_method you specified \[invalid\] must be one of/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'validate unsupported auth_method' do
|
||||
let :pre_condition do
|
||||
<<-EOS
|
||||
class { 'postgresql::globals':
|
||||
version => '9.0',
|
||||
}
|
||||
class { 'postgresql::server': }
|
||||
EOS
|
||||
end
|
||||
|
||||
let :params do
|
||||
{
|
||||
:type => 'local',
|
||||
:database => 'all',
|
||||
:user => 'all',
|
||||
:address => '0.0.0.0/0',
|
||||
:auth_method => 'peer',
|
||||
:target => target,
|
||||
}
|
||||
end
|
||||
|
||||
it 'should fail parsing when auth_method is not valid' do
|
||||
expect {subject}.to raise_error(Puppet::Error,
|
||||
/The auth_method you specified \[peer\] must be one of: trust, reject, md5, sha1, password, gss, sspi, krb5, ident, ldap, radius, cert, pam/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'validate supported auth_method' do
|
||||
let :pre_condition do
|
||||
<<-EOS
|
||||
class { 'postgresql::globals':
|
||||
version => '9.2',
|
||||
}
|
||||
class { 'postgresql::server': }
|
||||
EOS
|
||||
end
|
||||
|
||||
let :params do
|
||||
{
|
||||
:type => 'local',
|
||||
:database => 'all',
|
||||
:user => 'all',
|
||||
:address => '0.0.0.0/0',
|
||||
:auth_method => 'peer',
|
||||
:target => target,
|
||||
}
|
||||
end
|
||||
|
||||
it do
|
||||
content = param('concat::fragment', 'pg_hba_rule_test', 'content')
|
||||
content.should =~ /local\s+all\s+all\s+0\.0\.0\.0\/0\s+peer/
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
23
modules/postgresql/spec/unit/defines/server/role_spec.rb
Normal file
23
modules/postgresql/spec/unit/defines/server/role_spec.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::server::role', :type => :define do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
|
||||
let :title do
|
||||
'test'
|
||||
end
|
||||
|
||||
let :params do
|
||||
{
|
||||
:password_hash => 'test',
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_postgresql__server__role('test') }
|
||||
end
|
|
@ -0,0 +1,27 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::server::table_grant', :type => :define do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
|
||||
let :title do
|
||||
'test'
|
||||
end
|
||||
|
||||
let :params do
|
||||
{
|
||||
:privilege => 'ALL',
|
||||
:db => 'test',
|
||||
:role => 'test',
|
||||
:table => 'foo',
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_postgresql__server__table_grant('test') }
|
||||
it { should contain_postgresql__server__grant('table:test') }
|
||||
end
|
|
@ -0,0 +1,23 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::server::tablespace', :type => :define do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
|
||||
let :title do
|
||||
'test'
|
||||
end
|
||||
|
||||
let :params do
|
||||
{
|
||||
:location => '/srv/data/foo',
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_postgresql__server__tablespace('test') }
|
||||
end
|
|
@ -0,0 +1,35 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql::validate_db_connection', :type => :define do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
|
||||
let :title do
|
||||
'test'
|
||||
end
|
||||
|
||||
describe 'should work with only default parameters' do
|
||||
it { should contain_postgresql__validate_db_connection('test') }
|
||||
end
|
||||
|
||||
describe 'should work with all parameters' do
|
||||
let :params do
|
||||
{
|
||||
:database_host => 'test',
|
||||
:database_name => 'test',
|
||||
:database_password => 'test',
|
||||
:database_username => 'test',
|
||||
:database_port => 5432,
|
||||
:run_as => 'postgresq',
|
||||
:sleep => 4,
|
||||
:tries => 30,
|
||||
}
|
||||
end
|
||||
it { should contain_postgresql__validate_db_connection('test') }
|
||||
end
|
||||
end
|
|
@ -0,0 +1,137 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql_acls_to_resources_hash', :type => :puppet_function do
|
||||
context 'individual transform tests' do
|
||||
it do
|
||||
input = 'local all postgres ident'
|
||||
result = {
|
||||
"postgresql class generated rule test 0"=>{
|
||||
"type"=>"local",
|
||||
"database"=>"all",
|
||||
"user"=>"postgres",
|
||||
"auth_method"=>"ident",
|
||||
"order"=>"100",
|
||||
},
|
||||
}
|
||||
|
||||
should run.with_params([input], 'test', 100).and_return(result)
|
||||
end
|
||||
|
||||
it do
|
||||
input = 'local all root ident'
|
||||
result = {
|
||||
"postgresql class generated rule test 0"=>{
|
||||
"type"=>"local",
|
||||
"database"=>"all",
|
||||
"user"=>"root",
|
||||
"auth_method"=>"ident",
|
||||
"order"=>"100",
|
||||
},
|
||||
}
|
||||
|
||||
should run.with_params([input], 'test', 100).and_return(result)
|
||||
end
|
||||
|
||||
it do
|
||||
input_array = [
|
||||
'local all all ident',
|
||||
]
|
||||
result = {
|
||||
"postgresql class generated rule test 0"=>{
|
||||
"type"=>"local",
|
||||
"database"=>"all",
|
||||
"user"=>"all",
|
||||
"auth_method"=>"ident",
|
||||
"order"=>"100",
|
||||
},
|
||||
}
|
||||
|
||||
should run.with_params(input_array, 'test', 100).and_return(result)
|
||||
end
|
||||
|
||||
it do
|
||||
input = 'host all all 127.0.0.1/32 md5'
|
||||
result = {
|
||||
"postgresql class generated rule test 0"=>{
|
||||
"type"=>"host",
|
||||
"database"=>"all",
|
||||
"user"=>"all",
|
||||
"address"=>"127.0.0.1/32",
|
||||
"auth_method"=>"md5",
|
||||
"order"=>"100",
|
||||
},
|
||||
}
|
||||
|
||||
should run.with_params([input], 'test', 100).and_return(result)
|
||||
end
|
||||
|
||||
it do
|
||||
input = 'host all all 0.0.0.0/0 md5'
|
||||
result = {
|
||||
"postgresql class generated rule test 0"=>{
|
||||
"type"=>"host",
|
||||
"database"=>"all",
|
||||
"user"=>"all",
|
||||
"address"=>"0.0.0.0/0",
|
||||
"auth_method"=>"md5",
|
||||
"order"=>"100",
|
||||
},
|
||||
}
|
||||
|
||||
should run.with_params([input], 'test', 100).and_return(result)
|
||||
end
|
||||
|
||||
it do
|
||||
input = 'host all all ::1/128 md5'
|
||||
result = {
|
||||
"postgresql class generated rule test 0"=>{
|
||||
"type"=>"host",
|
||||
"database"=>"all",
|
||||
"user"=>"all",
|
||||
"address"=>"::1/128",
|
||||
"auth_method"=>"md5",
|
||||
"order"=>"100",
|
||||
},
|
||||
}
|
||||
|
||||
should run.with_params([input], 'test', 100).and_return(result)
|
||||
end
|
||||
|
||||
it do
|
||||
input = 'host all all 1.1.1.1 255.255.255.0 md5'
|
||||
result = {
|
||||
"postgresql class generated rule test 0"=>{
|
||||
"type"=>"host",
|
||||
"database"=>"all",
|
||||
"user"=>"all",
|
||||
"address"=>"1.1.1.1 255.255.255.0",
|
||||
"auth_method"=>"md5",
|
||||
"order"=>"100",
|
||||
},
|
||||
}
|
||||
|
||||
should run.with_params([input], 'test', 100).and_return(result)
|
||||
end
|
||||
|
||||
it do
|
||||
input = 'host all all 1.1.1.1 255.255.255.0 ldap ldapserver=ldap.example.net ldapprefix="cn=" ldapsuffix=", dc=example, dc=net"'
|
||||
result = {
|
||||
"postgresql class generated rule test 0"=>{
|
||||
"type"=>"host",
|
||||
"database"=>"all",
|
||||
"user"=>"all",
|
||||
"address"=>"1.1.1.1 255.255.255.0",
|
||||
"auth_method"=>"ldap",
|
||||
"auth_option"=>"ldapserver=ldap.example.net ldapprefix=\"cn=\" ldapsuffix=\", dc=example, dc=net\"",
|
||||
"order"=>"100",
|
||||
},
|
||||
}
|
||||
|
||||
should run.with_params([input], 'test', 100).and_return(result)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should return an empty hash when input is empty array' do
|
||||
should run.with_params([], 'test', 100).and_return({})
|
||||
end
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql_escape', :type => :puppet_function do
|
||||
it { should run.with_params('foo').
|
||||
and_return('$$foo$$') }
|
||||
end
|
||||
describe 'postgresql_escape', :type => :puppet_function do
|
||||
it { should run.with_params('fo$$o').
|
||||
and_return('$ed$fo$$o$ed$') }
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql_password', :type => :puppet_function do
|
||||
it { should run.with_params('foo', 'bar').
|
||||
and_return('md596948aad3fcae80c08a35c9b5958cd89') }
|
||||
end
|
|
@ -0,0 +1,112 @@
|
|||
require 'spec_helper'
|
||||
require "tempfile"
|
||||
|
||||
provider_class = Puppet::Type.type(:postgresql_conf).provider(:parsed)
|
||||
|
||||
describe provider_class do
|
||||
let(:title) { 'postgresql_conf' }
|
||||
let(:provider) {
|
||||
conf_class = Puppet::Type.type(:postgresql_conf)
|
||||
provider = conf_class.provider(:parsed)
|
||||
conffile = tmpfilename('postgresql.conf')
|
||||
provider.any_instance.stubs(:target).returns conffile
|
||||
provider
|
||||
}
|
||||
|
||||
before do
|
||||
end
|
||||
|
||||
after :each do
|
||||
provider.initvars
|
||||
end
|
||||
|
||||
describe "simple configuration that should be allowed" do
|
||||
it "should parse a simple ini line" do
|
||||
provider.parse_line("listen_addreses = '*'").should ==
|
||||
{ :name=>"listen_addreses", :value=>"*", :comment=>nil, :record_type=>:parsed }
|
||||
end
|
||||
|
||||
it "should parse a simple ini line (2)" do
|
||||
provider.parse_line(" listen_addreses = '*'").should ==
|
||||
{ :name=>"listen_addreses", :value=>"*", :comment=>nil, :record_type=>:parsed }
|
||||
end
|
||||
|
||||
it "should parse a simple ini line (3)" do
|
||||
provider.parse_line("listen_addreses = '*' # dont mind me").should ==
|
||||
{ :name=>"listen_addreses", :value=>"*", :comment=>"dont mind me", :record_type=>:parsed }
|
||||
end
|
||||
|
||||
it "should parse a comment" do
|
||||
provider.parse_line("# dont mind me").should ==
|
||||
{ :line=>"# dont mind me", :record_type=>:comment }
|
||||
end
|
||||
|
||||
it "should parse a comment (2)" do
|
||||
provider.parse_line(" \t# dont mind me").should ==
|
||||
{ :line=>" \t# dont mind me", :record_type=>:comment }
|
||||
end
|
||||
|
||||
it "should allow includes" do
|
||||
provider.parse_line("include puppetextra").should ==
|
||||
{ :name=>"include", :value=>"puppetextra", :comment=>nil, :record_type=>:parsed }
|
||||
end
|
||||
|
||||
it "should allow numbers thorugh without quotes" do
|
||||
provider.parse_line("wal_keep_segments = 32").should ==
|
||||
{ :name=>"wal_keep_segments", :value=>"32", :comment=>nil, :record_type=>:parsed }
|
||||
end
|
||||
|
||||
it "should allow blanks thorugh " do
|
||||
provider.parse_line("").should ==
|
||||
{ :line=>"", :record_type=>:blank }
|
||||
end
|
||||
|
||||
it "should parse keys with dots " do
|
||||
provider.parse_line("auto_explain.log_min_duration = 1ms").should ==
|
||||
{ :name => "auto_explain.log_min_duration", :value => "1ms", :comment => nil, :record_type => :parsed }
|
||||
end
|
||||
end
|
||||
|
||||
describe "configuration that should be set" do
|
||||
it "should set comment lines" do
|
||||
provider.to_line({ :line=>"# dont mind me", :record_type=>:comment }).should ==
|
||||
'# dont mind me'
|
||||
end
|
||||
|
||||
it "should set blank lines" do
|
||||
provider.to_line({ :line=>"", :record_type=>:blank }).should ==
|
||||
''
|
||||
end
|
||||
|
||||
it "should set simple configuration" do
|
||||
provider.to_line({:name=>"listen_addresses", :value=>"*", :comment=>nil, :record_type=>:parsed }).should ==
|
||||
"listen_addresses = '*'"
|
||||
end
|
||||
|
||||
it "should set simple configuration with period in name" do
|
||||
provider.to_line({:name => "auto_explain.log_min_duration", :value => '100ms', :comment => nil, :record_type => :parsed }).should ==
|
||||
"auto_explain.log_min_duration = 100ms"
|
||||
end
|
||||
|
||||
it "should set simple configuration even with comments" do
|
||||
provider.to_line({:name=>"listen_addresses", :value=>"*", :comment=>'dont mind me', :record_type=>:parsed }).should ==
|
||||
"listen_addresses = '*' # dont mind me"
|
||||
end
|
||||
|
||||
it 'should quote includes' do
|
||||
provider.to_line( {:name=>"include", :value=>"puppetextra", :comment=>nil, :record_type=>:parsed }).should ==
|
||||
"include 'puppetextra'"
|
||||
end
|
||||
|
||||
it 'should quote multiple words' do
|
||||
provider.to_line( {:name=>"archive_command", :value=>"rsync up", :comment=>nil, :record_type=>:parsed }).should ==
|
||||
"archive_command = 'rsync up'"
|
||||
end
|
||||
|
||||
it 'shouldn\'t quote numbers' do
|
||||
provider.to_line( {:name=>"wal_segments", :value=>"32", :comment=>nil, :record_type=>:parsed }).should ==
|
||||
"wal_segments = 32"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Puppet::Type.type(:postgresql_psql).provider(:ruby) do
|
||||
let(:name) { 'rspec psql test' }
|
||||
let(:resource) do
|
||||
Puppet::Type.type(:postgresql_psql).new({ :name => name, :provider => :ruby }.merge attributes)
|
||||
end
|
||||
|
||||
let(:provider) { resource.provider }
|
||||
|
||||
context("#run_sql_command") do
|
||||
describe "with default attributes" do
|
||||
let(:attributes) do { :db => 'spec_db' } end
|
||||
|
||||
it "executes with the given psql_path on the given DB" do
|
||||
expect(provider).to receive(:run_command).with(['psql', '-d',
|
||||
attributes[:db], '-t', '-c', 'SELECT something'], 'postgres',
|
||||
'postgres')
|
||||
|
||||
provider.run_sql_command("SELECT something")
|
||||
end
|
||||
end
|
||||
describe "with psql_path and db" do
|
||||
let(:attributes) do {
|
||||
:psql_path => '/opt/postgres/psql',
|
||||
:psql_user => 'spec_user',
|
||||
:psql_group => 'spec_group',
|
||||
:cwd => '/spec',
|
||||
:db => 'spec_db'
|
||||
} end
|
||||
|
||||
it "executes with the given psql_path on the given DB" do
|
||||
expect(Dir).to receive(:chdir).with(attributes[:cwd]).and_yield
|
||||
expect(provider).to receive(:run_command).with([attributes[:psql_path],
|
||||
'-d', attributes[:db], '-t', '-c', 'SELECT something'],
|
||||
attributes[:psql_user], attributes[:psql_group])
|
||||
|
||||
provider.run_sql_command("SELECT something")
|
||||
end
|
||||
end
|
||||
describe "with search_path string" do
|
||||
let(:attributes) do {
|
||||
:search_path => "schema1"
|
||||
} end
|
||||
|
||||
it "executes with the given search_path" do
|
||||
expect(provider).to receive(:run_command).with(['psql', '-t', '-c',
|
||||
'set search_path to schema1; SELECT something'],
|
||||
'postgres', 'postgres')
|
||||
|
||||
provider.run_sql_command("SELECT something")
|
||||
end
|
||||
end
|
||||
describe "with search_path array" do
|
||||
let(:attributes) do {
|
||||
:search_path => ['schema1','schema2'],
|
||||
} end
|
||||
|
||||
it "executes with the given search_path" do
|
||||
expect(provider).to receive(:run_command).with(['psql', '-t', '-c',
|
||||
'set search_path to schema1,schema2; SELECT something'],
|
||||
'postgres',
|
||||
'postgres'
|
||||
)
|
||||
|
||||
provider.run_sql_command("SELECT something")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context("#command") do
|
||||
context "when unless is specified" do
|
||||
[:true, :false, true, false].each do |refresh|
|
||||
context "and refreshonly is #{refresh}" do
|
||||
let(:attributes) { {
|
||||
:command => 'SELECT something',
|
||||
:db => 'spec_db',
|
||||
:unless => 'SELECT something',
|
||||
:refreshonly => refresh
|
||||
} }
|
||||
|
||||
it "does not fail when the status is successful" do
|
||||
expect(provider).to receive(:run_unless_sql_command).and_return ["1 row returned", 0]
|
||||
provider.command
|
||||
end
|
||||
|
||||
it "returns the given command when rows are returned" do
|
||||
expect(provider).to receive(:run_unless_sql_command).and_return ["1 row returned", 0]
|
||||
expect(provider.command).to eq("SELECT something")
|
||||
end
|
||||
|
||||
it "does not return the given command when no rows are returned" do
|
||||
expect(provider).to receive(:run_unless_sql_command).and_return ["0 rows returned", 0]
|
||||
expect(provider.command).to_not eq("SELECT something")
|
||||
end
|
||||
|
||||
it "raises an error when the sql command fails" do
|
||||
allow(provider).to receive(:run_unless_sql_command).and_return ["Something went wrong", 1]
|
||||
expect { provider.command }.to raise_error(Puppet::Error, /Something went wrong/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when unless is not specified" do
|
||||
context "and refreshonly is true" do
|
||||
let(:attributes) do {
|
||||
:command => 'SELECT something',
|
||||
:db => 'spec_db',
|
||||
:refreshonly => :true
|
||||
} end
|
||||
it "does not run unless sql command" do
|
||||
expect(provider).to_not receive(:run_unless_sql_command)
|
||||
provider.command
|
||||
end
|
||||
|
||||
it "returns the given command do disable sync" do
|
||||
expect(provider.command).to eq("SELECT something")
|
||||
end
|
||||
end
|
||||
|
||||
context "and refreshonly is false" do
|
||||
let(:attributes) do {
|
||||
:command => 'SELECT something',
|
||||
:db => 'spec_db',
|
||||
:refreshonly => :false
|
||||
} end
|
||||
it "does not run unless sql command" do
|
||||
expect(provider).to_not receive(:run_unless_sql_command)
|
||||
provider.command
|
||||
end
|
||||
|
||||
it "does not return the command so as to enable sync" do
|
||||
expect(provider.command).to_not eq("SELECT something")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,92 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Puppet::Type.type(:postgresql_psql), "when validating attributes" do
|
||||
[:name, :unless, :db, :psql_path, :psql_user, :psql_group].each do |attr|
|
||||
it "should have a #{attr} parameter" do
|
||||
expect(Puppet::Type.type(:postgresql_psql).attrtype(attr)).to eq(:param)
|
||||
end
|
||||
end
|
||||
|
||||
[:command].each do |attr|
|
||||
it "should have a #{attr} property" do
|
||||
expect(Puppet::Type.type(:postgresql_psql).attrtype(attr)).to eq(:property)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe Puppet::Type.type(:postgresql_psql), :unless => Puppet.features.microsoft_windows? do
|
||||
subject do
|
||||
Puppet::Type.type(:postgresql_psql).new({:name => 'rspec'}.merge attributes)
|
||||
end
|
||||
|
||||
describe "available attributes" do
|
||||
{
|
||||
:name => "rspec",
|
||||
:command => "SELECT stuff",
|
||||
:unless => "SELECT other,stuff",
|
||||
:db => "postgres",
|
||||
:psql_path => "/bin/false",
|
||||
:psql_user => "postgres",
|
||||
:psql_group => "postgres",
|
||||
:cwd => "/var/lib",
|
||||
:refreshonly => :true,
|
||||
:search_path => [ "schema1", "schema2"]
|
||||
}.each do |attr, value|
|
||||
context attr do
|
||||
let(:attributes) do { attr => value } end
|
||||
its([attr]) { should == value }
|
||||
end
|
||||
end
|
||||
|
||||
context "default values" do
|
||||
let(:attributes) do {} end
|
||||
its([:psql_path]) { should eq("psql") }
|
||||
its([:psql_user]) { should eq("postgres") }
|
||||
its([:psql_group]) { should eq("postgres") }
|
||||
its([:cwd]) { should eq("/tmp") }
|
||||
its(:refreshonly?) { should be_false }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#refreshonly" do
|
||||
[true, :true].each do |refreshonly|
|
||||
context "=> #{refreshonly.inspect}" do
|
||||
let(:attributes) do { :refreshonly => refreshonly } end
|
||||
it "has a value of true" do
|
||||
expect(subject.refreshonly?).to be_true
|
||||
end
|
||||
it "will not enforce command on sync because refresh() will be called" do
|
||||
expect(subject.provider).to_not receive(:command=)
|
||||
subject.property(:command).sync
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
[false, :false].each do |refreshonly|
|
||||
context "=> #{refreshonly.inspect}" do
|
||||
let(:attributes) do { :refreshonly => refreshonly } end
|
||||
it "has a value of false" do
|
||||
expect(subject.refreshonly?).to be_false
|
||||
end
|
||||
it "will enforce command on sync because refresh() will not be called" do
|
||||
expect(subject.provider).to receive(:command=)
|
||||
subject.property(:command).sync
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
## If we refresh the resource, the command should always be run regardless of
|
||||
## refreshonly
|
||||
describe "when responding to refresh" do
|
||||
[true, :true, false, :false].each do |refreshonly|
|
||||
context "with refreshonly => #{refreshonly.inspect}" do
|
||||
let(:attributes) do { :refreshonly => refreshonly } end
|
||||
it "will enforce command on sync" do
|
||||
expect(subject.provider).to receive(:command=)
|
||||
subject.refresh
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
50
modules/postgresql/spec/unit/type/postgresql_conf_spec.rb
Normal file
50
modules/postgresql/spec/unit/type/postgresql_conf_spec.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
#! /usr/bin/env ruby
|
||||
require 'spec_helper'
|
||||
|
||||
describe Puppet::Type.type(:postgresql_conf) do
|
||||
before do
|
||||
@provider_class = described_class.provide(:simple) { mk_resource_methods }
|
||||
@provider_class.stubs(:suitable?).returns true
|
||||
described_class.stubs(:defaultprovider).returns @provider_class
|
||||
end
|
||||
|
||||
describe "namevar validation" do
|
||||
it "should have :name as its namevar" do
|
||||
described_class.key_attributes.should == [:name]
|
||||
end
|
||||
it "should not invalid names" do
|
||||
expect { described_class.new(:name => 'foo bar') }.to raise_error(Puppet::Error, /Invalid value/)
|
||||
end
|
||||
it "should allow dots in names" do
|
||||
expect { described_class.new(:name => 'foo.bar') }.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe "when validating attributes" do
|
||||
[:name, :provider].each do |param|
|
||||
it "should have a #{param} parameter" do
|
||||
described_class.attrtype(param).should == :param
|
||||
end
|
||||
end
|
||||
|
||||
[:value, :target].each do |property|
|
||||
it "should have a #{property} property" do
|
||||
described_class.attrtype(property).should == :property
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "when validating values" do
|
||||
describe "ensure" do
|
||||
it "should support present as a value for ensure" do
|
||||
expect { described_class.new(:name => 'foo', :ensure => :present) }.to_not raise_error
|
||||
end
|
||||
it "should support absent as a value for ensure" do
|
||||
expect { described_class.new(:name => 'foo', :ensure => :absent) }.to_not raise_error
|
||||
end
|
||||
it "should not support other values" do
|
||||
expect { described_class.new(:name => 'foo', :ensure => :foo) }.to raise_error(Puppet::Error, /Invalid value/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue