Merge pull request #449 from apenney/spec_tests_rewrite
Spec tests rewrite
This commit is contained in:
commit
46103e7c45
57 changed files with 364 additions and 1505 deletions
28
spec/acceptance/alternative_port_spec.rb
Normal file
28
spec/acceptance/alternative_port_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
# These tests ensure that postgres can change itself to an alternative port
|
||||
# properly.
|
||||
describe 'postgres::server', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
it 'on an alternative port' do
|
||||
pp = <<-EOS
|
||||
class { 'postgresql::server': port => '5433' }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
describe port(5433) do
|
||||
it { is_expected.to be_listening }
|
||||
end
|
||||
|
||||
it 'can connect with psql' do
|
||||
psql('-p 5433 --command="\l" postgres', 'postgres') do |r|
|
||||
expect(r.stdout).to match(/List of databases/)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
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
|
|
@ -1,47 +0,0 @@
|
|||
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
|
|
@ -1,28 +0,0 @@
|
|||
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
|
35
spec/acceptance/db_spec.rb
Normal file
35
spec/acceptance/db_spec.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::db', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
it 'creates a database' do
|
||||
begin
|
||||
tmpdir = default.tmpdir('postgresql')
|
||||
pp = <<-EOS
|
||||
class { 'postgresql::server': }
|
||||
postgresql::server::tablespace { 'postgresql_test_db':
|
||||
location => '#{tmpdir}',
|
||||
} ->
|
||||
postgresql::server::db { 'postgresql_test_db':
|
||||
user => 'test',
|
||||
password => 'test1',
|
||||
tablespace => 'postgresql_test_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
|
||||
|
||||
psql('--command="SELECT 1 FROM pg_roles WHERE rolname=\'test\'"') do |r|
|
||||
expect(r.stdout).to match(/\(1 row\)/)
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop database postgresql_test_db" postgres')
|
||||
psql('--command="DROP USER test"')
|
||||
end
|
||||
end
|
||||
end
|
28
spec/acceptance/default_parameters_spec.rb
Normal file
28
spec/acceptance/default_parameters_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
# These tests are designed to ensure that the module, when ran with defaults,
|
||||
# sets up everything correctly and allows us to connect to Postgres.
|
||||
describe 'postgres::server', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
it 'with defaults' do
|
||||
pp = <<-EOS
|
||||
class { 'postgresql::server': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
describe port(5432) do
|
||||
it { is_expected.to be_listening }
|
||||
end
|
||||
|
||||
it 'can connect with psql' do
|
||||
psql('--command="\l" postgres', 'postgres') do |r|
|
||||
expect(r.stdout).to match(/List of databases/)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
32
spec/acceptance/firewall_default_parameters_spec.rb
Normal file
32
spec/acceptance/firewall_default_parameters_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
# These tests are designed to ensure that the module with firewall enabled,
|
||||
# when ran with defaults, sets up everything correctly and allows us to connect
|
||||
# to Postgres.
|
||||
describe 'postgres::server with firewall', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
it 'with defaults' do
|
||||
pp = <<-EOS
|
||||
class { 'firewall': } ->
|
||||
class { 'postgresql::server':
|
||||
manage_firewall => true,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
describe port(5432) do
|
||||
it { is_expected.to be_listening }
|
||||
end
|
||||
|
||||
it 'can connect with psql' do
|
||||
psql('--command="\l" postgres', 'postgres') do |r|
|
||||
expect(r.stdout).to match(/List of databases/)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
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
|
|
@ -1,20 +0,0 @@
|
|||
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
|
|
@ -1,17 +0,0 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::lib::perl:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
# Cleanup after tests have ran
|
||||
apply_manifest("class { 'postgresql::lib::perl': package_ensure => purged }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'test loading class with no parameters' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::lib::perl': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
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
|
|
@ -1,29 +0,0 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'postgresql::server::postgis:', :unless => fact('operatingsystem') == 'RedHat' && fact('operatingsystemrelease') == '7.0' do
|
||||
after :all do
|
||||
# Cleanup after tests have ran, remove both postgis and server as postgis
|
||||
# pulls in the server based packages.
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server':
|
||||
ensure => absent,
|
||||
}
|
||||
class { 'postgresql::server::postgis':
|
||||
package_ensure => purged,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'test loading class with no parameters' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::globals': manage_package_repo => true }
|
||||
class { 'postgresql::server': }
|
||||
class { 'postgresql::server::postgis': }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
|
@ -1,54 +1,44 @@
|
|||
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
|
||||
describe 'postgresql_psql', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
|
||||
it 'should always run SQL' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
pp = <<-EOS
|
||||
class { 'postgresql::server': } ->
|
||||
postgresql_psql { 'foobar':
|
||||
db => 'postgres',
|
||||
psql_user => 'postgres',
|
||||
command => 'select 1',
|
||||
require => Class['postgresql::server'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :expect_changes => true)
|
||||
end
|
||||
|
||||
it 'should run some SQL when the unless query returns no rows' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
pp = <<-EOS
|
||||
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)
|
||||
apply_manifest(pp, :expect_changes => true)
|
||||
end
|
||||
|
||||
it 'should not run SQL when the unless query returns rows' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
pp = <<-EOS
|
||||
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
|
||||
|
||||
|
@ -57,46 +47,41 @@ describe 'postgresql_psql:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osf
|
|||
end
|
||||
|
||||
it 'should not run SQL when refreshed and the unless query returns rows' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
pp = <<-EOS
|
||||
class { 'postgresql::server': } ->
|
||||
notify { 'trigger': } ~>
|
||||
postgresql_psql { 'foobar':
|
||||
db => 'postgres',
|
||||
psql_user => 'postgres',
|
||||
command => 'invalid sql statement',
|
||||
unless => 'select 1 where 1=1',
|
||||
require => Class['postgresql::server'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :expect_changes => true)
|
||||
end
|
||||
|
||||
context 'with refreshonly' do
|
||||
it 'should not run SQL when the unless query returns no rows' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
pp = <<-EOS
|
||||
class { 'postgresql::server': } ->
|
||||
postgresql_psql { 'foobar':
|
||||
db => 'postgres',
|
||||
psql_user => 'postgres',
|
||||
command => 'select 1',
|
||||
unless => 'select 1 where 1=2',
|
||||
refreshonly => true,
|
||||
require => Class['postgresql::server'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
it 'should run SQL when refreshed and the unless query returns no rows' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
class { 'postgresql::server': } ->
|
||||
notify { 'trigger': } ~>
|
||||
postgresql_psql { 'foobar':
|
||||
db => 'postgres',
|
||||
|
@ -104,18 +89,16 @@ describe 'postgresql_psql:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osf
|
|||
command => 'select 1',
|
||||
unless => 'select 1 where 1=2',
|
||||
refreshonly => true,
|
||||
require => Class['postgresql::server'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :expect_changes => true)
|
||||
end
|
||||
|
||||
it 'should not run SQL when refreshed and the unless query returns rows' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
class { 'postgresql::server': } ->
|
||||
notify { 'trigger': } ~>
|
||||
postgresql_psql { 'foobar':
|
||||
db => 'postgres',
|
||||
|
@ -123,12 +106,11 @@ describe 'postgresql_psql:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osf
|
|||
command => 'invalid sql query',
|
||||
unless => 'select 1 where 1=1',
|
||||
refreshonly => true,
|
||||
require => Class['postgresql::server'],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :expect_changes => true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
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
|
||||
|
||||
it 'should correctly set a quotes-required string' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::config_entry { 'log_directory':
|
||||
value => '/tmp/testfile',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
|
||||
psql('--command="show all" postgres') do |r|
|
||||
r.stdout.should =~ /log_directory.+\/tmp\/testfile/
|
||||
r.stderr.should be_empty
|
||||
r.exit_code.should == 0
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,48 +0,0 @@
|
|||
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
|
|
@ -1,54 +0,0 @@
|
|||
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
|
||||
|
||||
describe 'postgresql::server::database: alternate port', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
it 'should idempotently create a db on a non-default port that we can connect to' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'postgresql_test_db'
|
||||
class { 'postgresql::server':
|
||||
port => 5433,
|
||||
}
|
||||
|
||||
postgresql::server::database { $db: }
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
psql('--command="select datname from pg_database" --port=5433 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" --port=5433 postgres')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,164 +0,0 @@
|
|||
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
|
||||
|
||||
it 'should take a dbname parameter' do
|
||||
begin
|
||||
pp = <<-EOS.unindent
|
||||
$db = 'postgresql_test_db'
|
||||
$dbname = 'postgresql_testtest_db'
|
||||
class { 'postgresql::server': }
|
||||
|
||||
postgresql::server::db { $db:
|
||||
dbname => $dbname,
|
||||
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_testtest_db') do |r|
|
||||
expect(r.stdout).to match(/postgresql_testtest_db/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
ensure
|
||||
psql('--command="drop database postgresql_testtest_db" postgres')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,49 +0,0 @@
|
|||
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
|
|
@ -1,72 +0,0 @@
|
|||
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
|
|
@ -1,25 +0,0 @@
|
|||
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
|
|
@ -1,116 +0,0 @@
|
|||
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
|
||||
|
||||
it 'should idempotently create a user with noinherit' do
|
||||
pp = <<-EOS.unindent
|
||||
$user = "postgresql_test_noinherit"
|
||||
$password = "postgresql_test_noinherit"
|
||||
|
||||
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,
|
||||
inherit => false,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
# Check that the user has noinherit set
|
||||
psql('--command="select rolname from pg_roles where not rolinherit" postgres', 'postgresql_test_noinherit') do |r|
|
||||
expect(r.stdout).to match(/postgresql_test_noinherit/)
|
||||
expect(r.stderr).to eq('')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,124 +0,0 @@
|
|||
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
|
|
@ -1,67 +0,0 @@
|
|||
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
|
|
@ -1,294 +0,0 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
# Hack around the fact that so far only Ubuntu 14.04 seems to have moved this
|
||||
# file. Can revisit if everyone else gets clever.
|
||||
|
||||
case fact('operatingsystem')
|
||||
when 'Ubuntu'
|
||||
case fact('operatingsystemrelease')
|
||||
when '14.04'
|
||||
pghba_file = '/etc/postgresql/9.3/main/pg_hba.conf'
|
||||
when '12.04'
|
||||
pghba_file = '/etc/postgresql/9.1/main/pg_hba.conf'
|
||||
end
|
||||
else
|
||||
pghba_file = '/var/lib/pgsql/data/pg_hba.conf'
|
||||
end
|
||||
|
||||
describe 'server:', :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::client': package_ensure => absent }
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
if fact('osfamily') == 'RedHat'
|
||||
shell('rpm -qa | grep postgres | xargs rpm -e')
|
||||
end
|
||||
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 file(pghba_file) do
|
||||
it { should be_file }
|
||||
it { should be_owned_by 'postgres' }
|
||||
it { should be_grouped_into 'postgres' }
|
||||
it { should be_mode 640 }
|
||||
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':
|
||||
manage_package_repo => true,
|
||||
version => '9.3',
|
||||
}
|
||||
class { 'postgresql::server':
|
||||
ensure => absent,
|
||||
} ->
|
||||
class { 'postgresql::client':
|
||||
package_ensure => absent,
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
if fact('osfamily') == 'RedHat'
|
||||
shell('rpm -qa | grep postgres | xargs rpm -e')
|
||||
end
|
||||
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'),
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
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
|
||||
|
||||
context 'test deprecating non-default version of postgresql to postgresql::server' do
|
||||
after :all do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::globals':
|
||||
version => '9.3',
|
||||
}
|
||||
class { 'postgresql::server':
|
||||
ensure => absent,
|
||||
} ->
|
||||
class { 'postgresql::client':
|
||||
package_ensure => absent,
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'raises a warning' do
|
||||
pp = <<-EOS.unindent
|
||||
class { 'postgresql::server':
|
||||
ensure => absent,
|
||||
version => '9.3',
|
||||
}
|
||||
EOS
|
||||
expect(apply_manifest(pp, :catch_failures => false).stderr).to match(/Passing "version" to postgresql::server is deprecated/i)
|
||||
end
|
||||
end
|
||||
|
||||
unless ((fact('osfamily') == 'RedHat' and fact('lsbmajdistrelease') == '5') ||
|
||||
fact('osfamily') == 'Debian')
|
||||
|
||||
context 'override locale and encoding' do
|
||||
before :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
|
||||
|
||||
if fact('osfamily') == 'RedHat' and fact('operatingsystemmajrelease') == '5'
|
||||
shell('iptables -F')
|
||||
end
|
||||
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
|
||||
|
||||
describe 'server on alternate port:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
after :all do
|
||||
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'sets up selinux' do
|
||||
pp = <<-EOS
|
||||
if $::osfamily == 'RedHat' and $::selinux == 'true' {
|
||||
$semanage_package = $::operatingsystemmajrelease ? {
|
||||
'5' => 'policycoreutils',
|
||||
default => 'policycoreutils-python',
|
||||
}
|
||||
|
||||
package { $semanage_package: ensure => installed }
|
||||
exec { 'set_postgres':
|
||||
command => 'semanage port -a -t postgresql_port_t -p tcp 5433',
|
||||
path => '/bin:/usr/bin/:/sbin:/usr/sbin',
|
||||
subscribe => Package[$semanage_package],
|
||||
refreshonly => true,
|
||||
}
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
|
||||
context 'test installing postgresql with alternate port' do
|
||||
it 'perform installation and make sure it is idempotent' do
|
||||
pp = <<-EOS.unindent
|
||||
class { "postgresql::server":
|
||||
port => 5433,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
describe port(5433) do
|
||||
it { should be_listening }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
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(/No preferred version defined or automatically detected/i)
|
||||
end
|
||||
it 'should fail for server' do
|
||||
pp = <<-EOS
|
||||
class { 'postgresql::server': }
|
||||
EOS
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/No preferred version defined or automatically detected/i)
|
||||
end
|
||||
end
|
|
@ -1,97 +0,0 @@
|
|||
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 'stops postgresql' do
|
||||
# First we stop postgresql.
|
||||
pp = <<-EOS
|
||||
class { 'postgresql::server':
|
||||
service_ensure => 'stopped',
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should keep retrying if database is down' do
|
||||
if fact('operatingsystem') == 'RedHat' && fact('operatingsystemrelease') =~ /^7/
|
||||
shell('nohup bash -c "sleep 10; systemctl start `basename /usr/lib/systemd/system/postgres*`" > /dev/null 2>&1 &')
|
||||
else
|
||||
shell('nohup bash -c "sleep 10; /etc/init.d/postgresql* start" > /dev/null 2>&1 &')
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
it 'starts postgresql' do
|
||||
pp = <<-EOS
|
||||
class { 'postgresql::server':
|
||||
service_ensure => 'running',
|
||||
}
|
||||
EOS
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
end
|
|
@ -32,3 +32,6 @@ end
|
|||
def param(type, title, param)
|
||||
param_value(catalogue, type, title, param)
|
||||
end
|
||||
|
||||
# With rspec-puppet v2.0 this allows coverage checks.
|
||||
#at_exit { RSpec::Puppet::Coverage.report! }
|
||||
|
|
|
@ -46,10 +46,31 @@ unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
|
|||
# Augeas is only used in one place, for Redhat.
|
||||
if fact('osfamily') == 'RedHat'
|
||||
install_package host, 'ruby-devel'
|
||||
install_package host, 'augeas-devel'
|
||||
install_package host, 'ruby-augeas'
|
||||
#install_package host, 'augeas-devel'
|
||||
#install_package host, 'ruby-augeas'
|
||||
end
|
||||
end
|
||||
# Set up selinux if appropriate.
|
||||
if fact('osfamily') == 'RedHat' && fact('selinux') == 'true'
|
||||
pp = <<-EOS
|
||||
if $::osfamily == 'RedHat' and $::selinux == 'true' {
|
||||
$semanage_package = $::operatingsystemmajrelease ? {
|
||||
'5' => 'policycoreutils',
|
||||
default => 'policycoreutils-python',
|
||||
}
|
||||
|
||||
package { $semanage_package: ensure => installed }
|
||||
exec { 'set_postgres':
|
||||
command => 'semanage port -a -t postgresql_port_t -p tcp 5433',
|
||||
path => '/bin:/usr/bin/:/sbin:/usr/sbin',
|
||||
subscribe => Package[$semanage_package],
|
||||
refreshonly => true,
|
||||
}
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -74,6 +95,8 @@ RSpec.configure do |c|
|
|||
on host, '/usr/sbin/locale-gen'
|
||||
on host, '/usr/sbin/update-locale'
|
||||
end
|
||||
|
||||
|
||||
if fact('osfamily') == 'RedHat'
|
||||
shell('yum -y install policycoreutils-python')
|
||||
shell('semanage port -a -t postgresql_port_t -p tcp 5433')
|
||||
|
@ -83,5 +106,7 @@ RSpec.configure do |c|
|
|||
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
|
||||
|
|
|
@ -18,7 +18,7 @@ describe 'postgresql::client', :type => :class do
|
|||
end
|
||||
|
||||
it 'should modify package' do
|
||||
should contain_package("postgresql-client").with({
|
||||
is_expected.to contain_package("postgresql-client").with({
|
||||
:ensure => 'absent',
|
||||
:name => 'mypackage',
|
||||
:tag => 'postgresql',
|
||||
|
@ -28,7 +28,7 @@ describe 'postgresql::client', :type => :class do
|
|||
|
||||
describe 'with no parameters' do
|
||||
it 'should create package with postgresql tag' do
|
||||
should contain_package('postgresql-client').with({
|
||||
is_expected.to contain_package('postgresql-client').with({
|
||||
:tag => 'postgresql',
|
||||
})
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ describe 'postgresql::globals', :type => :class do
|
|||
|
||||
describe 'with no parameters' do
|
||||
it 'should work' do
|
||||
should contain_class("postgresql::globals")
|
||||
is_expected.to contain_class("postgresql::globals")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -24,7 +24,7 @@ describe 'postgresql::globals', :type => :class do
|
|||
}
|
||||
end
|
||||
it 'should pull in class postgresql::repo' do
|
||||
should contain_class("postgresql::repo")
|
||||
is_expected.to contain_class("postgresql::repo")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,5 +8,5 @@ describe 'postgresql::lib::devel', :type => :class do
|
|||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
it { should contain_class("postgresql::lib::devel") }
|
||||
it { is_expected.to contain_class("postgresql::lib::devel") }
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ describe 'postgresql::lib::java', :type => :class do
|
|||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
it { should contain_package('postgresql-jdbc').with(
|
||||
it { is_expected.to contain_package('postgresql-jdbc').with(
|
||||
:name => 'libpostgresql-jdbc-java',
|
||||
:ensure => 'present',
|
||||
:tag => 'postgresql'
|
||||
|
@ -23,7 +23,7 @@ describe 'postgresql::lib::java', :type => :class do
|
|||
:operatingsystemrelease => '6.4',
|
||||
}
|
||||
end
|
||||
it { should contain_package('postgresql-jdbc').with(
|
||||
it { is_expected.to contain_package('postgresql-jdbc').with(
|
||||
:name => 'postgresql-jdbc',
|
||||
:ensure => 'present',
|
||||
:tag => 'postgresql'
|
||||
|
@ -32,7 +32,7 @@ describe 'postgresql::lib::java', :type => :class do
|
|||
let :params do
|
||||
{:package_ensure => 'latest', :package_name => 'somepackage'}
|
||||
end
|
||||
it { should contain_package('postgresql-jdbc').with(
|
||||
it { is_expected.to contain_package('postgresql-jdbc').with(
|
||||
:name => 'somepackage',
|
||||
:ensure => 'latest',
|
||||
:tag => 'postgresql'
|
||||
|
|
|
@ -9,7 +9,7 @@ describe 'postgresql::lib::perl', :type => :class do
|
|||
:operatingsystemrelease => '6.4',
|
||||
}
|
||||
end
|
||||
it { should contain_package('perl-DBD-Pg').with(
|
||||
it { is_expected.to contain_package('perl-DBD-Pg').with(
|
||||
:name => 'perl-DBD-Pg',
|
||||
:ensure => 'present'
|
||||
)}
|
||||
|
@ -22,7 +22,7 @@ describe 'postgresql::lib::perl', :type => :class do
|
|||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
it { should contain_package('perl-DBD-Pg').with(
|
||||
it { is_expected.to contain_package('perl-DBD-Pg').with(
|
||||
:name => 'libdbd-pg-perl',
|
||||
:ensure => 'present'
|
||||
)}
|
||||
|
|
|
@ -9,7 +9,7 @@ describe 'postgresql::lib::python', :type => :class do
|
|||
:operatingsystemrelease => '6.4',
|
||||
}
|
||||
end
|
||||
it { should contain_package('python-psycopg2').with(
|
||||
it { is_expected.to contain_package('python-psycopg2').with(
|
||||
:name => 'python-psycopg2',
|
||||
:ensure => 'present'
|
||||
)}
|
||||
|
@ -22,7 +22,7 @@ describe 'postgresql::lib::python', :type => :class do
|
|||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
it { should contain_package('python-psycopg2').with(
|
||||
it { is_expected.to contain_package('python-psycopg2').with(
|
||||
:name => 'python-psycopg2',
|
||||
:ensure => 'present'
|
||||
)}
|
||||
|
|
|
@ -8,5 +8,5 @@ describe 'postgresql::params', :type => :class do
|
|||
:operatingsystemrelease => '6.0',
|
||||
}
|
||||
end
|
||||
it { should contain_class("postgresql::params") }
|
||||
it { is_expected.to contain_class("postgresql::params") }
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ describe 'postgresql::repo', :type => :class do
|
|||
|
||||
describe 'with no parameters' do
|
||||
it 'should instantiate apt_postgresql_org class' do
|
||||
should contain_class('postgresql::repo::apt_postgresql_org')
|
||||
is_expected.to contain_class('postgresql::repo::apt_postgresql_org')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ describe 'postgresql::server::contrib', :type => :class do
|
|||
end
|
||||
|
||||
it 'should create package with correct params' do
|
||||
should contain_package('postgresql-contrib').with({
|
||||
is_expected.to contain_package('postgresql-contrib').with({
|
||||
:ensure => 'absent',
|
||||
:name => 'mypackage',
|
||||
:tag => 'postgresql',
|
||||
|
@ -36,7 +36,7 @@ describe 'postgresql::server::contrib', :type => :class do
|
|||
|
||||
describe 'with no parameters' do
|
||||
it 'should create package with postgresql tag' do
|
||||
should contain_package('postgresql-contrib').with({
|
||||
is_expected.to contain_package('postgresql-contrib').with({
|
||||
:tag => 'postgresql',
|
||||
})
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ describe 'postgresql::server::initdb', :type => :class do
|
|||
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
||||
}
|
||||
end
|
||||
it { should contain_file('/var/lib/pgsql/data').with_ensure('directory') }
|
||||
it { is_expected.to contain_file('/var/lib/pgsql/data').with_ensure('directory') }
|
||||
end
|
||||
describe 'on Amazon' do
|
||||
let :facts do
|
||||
|
@ -30,7 +30,7 @@ describe 'postgresql::server::initdb', :type => :class do
|
|||
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
||||
}
|
||||
end
|
||||
it { should contain_file('/var/lib/pgsql9/data').with_ensure('directory') }
|
||||
it { is_expected.to contain_file('/var/lib/pgsql9/data').with_ensure('directory') }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@ describe 'postgresql::server::plperl', :type => :class do
|
|||
end
|
||||
|
||||
describe 'with no parameters' do
|
||||
it { should contain_class("postgresql::server::plperl") }
|
||||
it { is_expected.to contain_class("postgresql::server::plperl") }
|
||||
it 'should create package' do
|
||||
should contain_package('postgresql-plperl').with({
|
||||
is_expected.to contain_package('postgresql-plperl').with({
|
||||
:ensure => 'present',
|
||||
:tag => 'postgresql',
|
||||
})
|
||||
|
@ -35,9 +35,9 @@ describe 'postgresql::server::plperl', :type => :class do
|
|||
}
|
||||
end
|
||||
|
||||
it { should contain_class("postgresql::server::plperl") }
|
||||
it { is_expected.to contain_class("postgresql::server::plperl") }
|
||||
it 'should create package with correct params' do
|
||||
should contain_package('postgresql-plperl').with({
|
||||
is_expected.to contain_package('postgresql-plperl').with({
|
||||
:ensure => 'absent',
|
||||
:name => 'mypackage',
|
||||
:tag => 'postgresql',
|
||||
|
|
|
@ -26,7 +26,7 @@ describe 'postgresql::server::postgis', :type => :class do
|
|||
end
|
||||
|
||||
it 'should create package with correct params' do
|
||||
should contain_package('postgresql-postgis').with({
|
||||
is_expected.to contain_package('postgresql-postgis').with({
|
||||
:ensure => 'absent',
|
||||
:name => 'mypackage',
|
||||
:tag => 'postgresql',
|
||||
|
@ -36,7 +36,7 @@ describe 'postgresql::server::postgis', :type => :class do
|
|||
|
||||
describe 'with no parameters' do
|
||||
it 'should create package with postgresql tag' do
|
||||
should contain_package('postgresql-postgis').with({
|
||||
is_expected.to contain_package('postgresql-postgis').with({
|
||||
:tag => 'postgresql',
|
||||
})
|
||||
end
|
||||
|
|
|
@ -14,28 +14,28 @@ describe 'postgresql::server', :type => :class do
|
|||
end
|
||||
|
||||
describe 'with no parameters' do
|
||||
it { should contain_class("postgresql::params") }
|
||||
it { should contain_class("postgresql::server") }
|
||||
it { is_expected.to contain_class("postgresql::params") }
|
||||
it { is_expected.to contain_class("postgresql::server") }
|
||||
it 'should validate connection' do
|
||||
should contain_postgresql__validate_db_connection('validate_service_is_running')
|
||||
is_expected.to contain_postgresql__validate_db_connection('validate_service_is_running')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'service_ensure => running' do
|
||||
let(:params) {{ :service_ensure => 'running' }}
|
||||
it { should contain_class("postgresql::params") }
|
||||
it { should contain_class("postgresql::server") }
|
||||
it { is_expected.to contain_class("postgresql::params") }
|
||||
it { is_expected.to contain_class("postgresql::server") }
|
||||
it 'should validate connection' do
|
||||
should contain_postgresql__validate_db_connection('validate_service_is_running')
|
||||
is_expected.to contain_postgresql__validate_db_connection('validate_service_is_running')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'service_ensure => stopped' do
|
||||
let(:params) {{ :service_ensure => 'stopped' }}
|
||||
it { should contain_class("postgresql::params") }
|
||||
it { should contain_class("postgresql::server") }
|
||||
it { is_expected.to contain_class("postgresql::params") }
|
||||
it { is_expected.to contain_class("postgresql::server") }
|
||||
it 'shouldnt validate connection' do
|
||||
should_not contain_postgresql__validate_db_connection('validate_service_is_running')
|
||||
is_expected.not_to contain_postgresql__validate_db_connection('validate_service_is_running')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -48,7 +48,7 @@ describe 'postgresql::server', :type => :class do
|
|||
end
|
||||
|
||||
it 'should create firewall rule' do
|
||||
should contain_firewall("5432 accept - postgres")
|
||||
is_expected.to contain_firewall("5432 accept - postgres")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -62,25 +62,25 @@ describe 'postgresql::server', :type => :class do
|
|||
end
|
||||
|
||||
it 'should make package purged' do
|
||||
should contain_package('postgresql-server').with({
|
||||
is_expected.to contain_package('postgresql-server').with({
|
||||
:ensure => 'purged',
|
||||
})
|
||||
end
|
||||
|
||||
it 'stop the service' do
|
||||
should contain_service('postgresqld').with({
|
||||
is_expected.to contain_service('postgresqld').with({
|
||||
:ensure => 'stopped',
|
||||
})
|
||||
end
|
||||
|
||||
it 'should remove datadir' do
|
||||
should contain_file('/my/path').with({
|
||||
is_expected.to contain_file('/my/path').with({
|
||||
:ensure => 'absent',
|
||||
})
|
||||
end
|
||||
|
||||
it 'should remove xlogdir' do
|
||||
should contain_file('/xlog/path').with({
|
||||
is_expected.to contain_file('/xlog/path').with({
|
||||
:ensure => 'absent',
|
||||
})
|
||||
end
|
||||
|
@ -94,13 +94,13 @@ describe 'postgresql::server', :type => :class do
|
|||
end
|
||||
|
||||
it 'should remove the package' do
|
||||
should contain_package('postgresql-server').with({
|
||||
is_expected.to contain_package('postgresql-server').with({
|
||||
:ensure => 'purged',
|
||||
})
|
||||
end
|
||||
|
||||
it 'should still enable the service' do
|
||||
should contain_service('postgresqld').with({
|
||||
is_expected.to contain_service('postgresqld').with({
|
||||
:ensure => 'running',
|
||||
})
|
||||
end
|
||||
|
@ -114,7 +114,7 @@ describe 'postgresql::server', :type => :class do
|
|||
end
|
||||
|
||||
it 'should contain proper initdb exec' do
|
||||
should contain_exec('postgresql_initdb')
|
||||
is_expected.to contain_exec('postgresql_initdb')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,7 +25,57 @@ describe 'postgresql::server::config_entry', :type => :define do
|
|||
end
|
||||
|
||||
let(:params) { { :ensure => 'present'} }
|
||||
it { should contain_postgresql__server__config_entry('config_entry') }
|
||||
it { is_expected.to contain_postgresql__server__config_entry('config_entry') }
|
||||
end
|
||||
|
||||
context 'ports' do
|
||||
context 'redhat 6' do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'RedHat',
|
||||
:operatingsystemrelease => '6.4',
|
||||
:kernel => 'Linux',
|
||||
:concat_basedir => tmpfilename('contrib'),
|
||||
:id => 'root',
|
||||
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
||||
}
|
||||
end
|
||||
let(:params) {{ :ensure => 'present', :name => 'port', :value => '5432' }}
|
||||
|
||||
it 'stops postgresql and changes the port' do
|
||||
is_expected.to contain_exec('postgresql_stop')
|
||||
is_expected.to contain_augeas('override PGPORT in /etc/sysconfig/pgsql/postgresql')
|
||||
end
|
||||
end
|
||||
context 'redhat 7' do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'RedHat',
|
||||
:operatingsystemrelease => '7.0',
|
||||
:kernel => 'Linux',
|
||||
:concat_basedir => tmpfilename('contrib'),
|
||||
:id => 'root',
|
||||
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
||||
}
|
||||
end
|
||||
let(:params) {{ :ensure => 'present', :name => 'port', :value => '5432' }}
|
||||
|
||||
it 'stops postgresql and changes the port' do
|
||||
is_expected.to contain_file('systemd-port-override')
|
||||
is_expected.to contain_exec('restart-systemd')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "passes values through appropriately" do
|
||||
let(:params) {{ :ensure => 'present', :name => 'check_function_bodies', :value => 'off' }}
|
||||
|
||||
it 'with no quotes' do
|
||||
is_expected.to contain_postgresql_conf('check_function_bodies').with({
|
||||
:name => 'check_function_bodies',
|
||||
:value => 'off' })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -29,6 +29,6 @@ describe 'postgresql::server::database_grant', :type => :define do
|
|||
"class {'postgresql::server':}"
|
||||
end
|
||||
|
||||
it { should contain_postgresql__server__database_grant('test') }
|
||||
it { should contain_postgresql__server__grant('database:test') }
|
||||
it { is_expected.to contain_postgresql__server__database_grant('test') }
|
||||
it { is_expected.to contain_postgresql__server__grant('database:test') }
|
||||
end
|
||||
|
|
|
@ -20,6 +20,6 @@ describe 'postgresql::server::database', :type => :define do
|
|||
"class {'postgresql::server':}"
|
||||
end
|
||||
|
||||
it { should contain_postgresql__server__database('test') }
|
||||
it { should contain_postgresql_psql("Check for existence of db 'test'") }
|
||||
it { is_expected.to contain_postgresql__server__database('test') }
|
||||
it { is_expected.to contain_postgresql_psql("Check for existence of db 'test'") }
|
||||
end
|
||||
|
|
|
@ -31,10 +31,10 @@ describe 'postgresql::server::db', :type => :define do
|
|||
"class {'postgresql::server':}"
|
||||
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') }
|
||||
it { is_expected.to contain_postgresql__server__db('test') }
|
||||
it { is_expected.to contain_postgresql__server__database('test').with_owner('tester') }
|
||||
it { is_expected.to contain_postgresql__server__role('test') }
|
||||
it { is_expected.to contain_postgresql__server__database_grant('GRANT test - ALL - test') }
|
||||
|
||||
end
|
||||
|
||||
|
@ -53,6 +53,6 @@ describe 'postgresql::server::db', :type => :define do
|
|||
"class {'postgresql::server':}"
|
||||
end
|
||||
|
||||
it { should contain_postgresql__server__database('testtest') }
|
||||
it { is_expected.to contain_postgresql__server__database('testtest') }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,5 +28,5 @@ describe 'postgresql::server::grant', :type => :define do
|
|||
"class {'postgresql::server':}"
|
||||
end
|
||||
|
||||
it { should contain_postgresql__server__grant('test') }
|
||||
it { is_expected.to contain_postgresql__server__grant('test') }
|
||||
end
|
||||
|
|
|
@ -37,7 +37,7 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do
|
|||
}
|
||||
end
|
||||
it do
|
||||
should contain_concat__fragment('pg_hba_rule_test').with({
|
||||
is_expected.to contain_concat__fragment('pg_hba_rule_test').with({
|
||||
:content => /host\s+all\s+all\s+1\.1\.1\.1\/24\s+md5/
|
||||
})
|
||||
end
|
||||
|
@ -60,7 +60,7 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do
|
|||
}
|
||||
end
|
||||
it do
|
||||
should contain_concat__fragment('pg_hba_rule_test').with({
|
||||
is_expected.to contain_concat__fragment('pg_hba_rule_test').with({
|
||||
:content => /local\s+all\s+all\s+ident/
|
||||
})
|
||||
end
|
||||
|
@ -85,7 +85,7 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do
|
|||
}
|
||||
end
|
||||
it do
|
||||
should contain_concat__fragment('pg_hba_rule_test').with({
|
||||
is_expected.to contain_concat__fragment('pg_hba_rule_test').with({
|
||||
:content => /host\s+all\s+all\s+0\.0\.0\.0\/0\s+ldap\s+foo=bar/
|
||||
})
|
||||
end
|
||||
|
@ -188,7 +188,7 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do
|
|||
end
|
||||
|
||||
it do
|
||||
should contain_concat__fragment('pg_hba_rule_test').with({
|
||||
is_expected.to contain_concat__fragment('pg_hba_rule_test').with({
|
||||
:content => /local\s+all\s+all\s+0\.0\.0\.0\/0\s+peer/
|
||||
})
|
||||
end
|
||||
|
|
|
@ -27,5 +27,5 @@ describe 'postgresql::server::role', :type => :define do
|
|||
"class {'postgresql::server':}"
|
||||
end
|
||||
|
||||
it { should contain_postgresql__server__role('test') }
|
||||
it { is_expected.to contain_postgresql__server__role('test') }
|
||||
end
|
||||
|
|
|
@ -30,6 +30,6 @@ describe 'postgresql::server::table_grant', :type => :define do
|
|||
"class {'postgresql::server':}"
|
||||
end
|
||||
|
||||
it { should contain_postgresql__server__table_grant('test') }
|
||||
it { should contain_postgresql__server__grant('table:test') }
|
||||
it { is_expected.to contain_postgresql__server__table_grant('test') }
|
||||
it { is_expected.to contain_postgresql__server__grant('table:test') }
|
||||
end
|
||||
|
|
|
@ -27,5 +27,5 @@ describe 'postgresql::server::tablespace', :type => :define do
|
|||
"class {'postgresql::server':}"
|
||||
end
|
||||
|
||||
it { should contain_postgresql__server__tablespace('test') }
|
||||
it { is_expected.to contain_postgresql__server__tablespace('test') }
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ describe 'postgresql::validate_db_connection', :type => :define do
|
|||
end
|
||||
|
||||
describe 'should work with only default parameters' do
|
||||
it { should contain_postgresql__validate_db_connection('test') }
|
||||
it { is_expected.to contain_postgresql__validate_db_connection('test') }
|
||||
end
|
||||
|
||||
describe 'should work with all parameters' do
|
||||
|
@ -30,6 +30,6 @@ describe 'postgresql::validate_db_connection', :type => :define do
|
|||
:tries => 30,
|
||||
}
|
||||
end
|
||||
it { should contain_postgresql__validate_db_connection('test') }
|
||||
it { is_expected.to contain_postgresql__validate_db_connection('test') }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ describe 'postgresql_acls_to_resources_hash', :type => :puppet_function do
|
|||
},
|
||||
}
|
||||
|
||||
should run.with_params([input], 'test', 100).and_return(result)
|
||||
is_expected.to run.with_params([input], 'test', 100).and_return(result)
|
||||
end
|
||||
|
||||
it do
|
||||
|
@ -29,7 +29,7 @@ describe 'postgresql_acls_to_resources_hash', :type => :puppet_function do
|
|||
},
|
||||
}
|
||||
|
||||
should run.with_params([input], 'test', 100).and_return(result)
|
||||
is_expected.to run.with_params([input], 'test', 100).and_return(result)
|
||||
end
|
||||
|
||||
it do
|
||||
|
@ -46,7 +46,7 @@ describe 'postgresql_acls_to_resources_hash', :type => :puppet_function do
|
|||
},
|
||||
}
|
||||
|
||||
should run.with_params(input_array, 'test', 100).and_return(result)
|
||||
is_expected.to run.with_params(input_array, 'test', 100).and_return(result)
|
||||
end
|
||||
|
||||
it do
|
||||
|
@ -62,7 +62,7 @@ describe 'postgresql_acls_to_resources_hash', :type => :puppet_function do
|
|||
},
|
||||
}
|
||||
|
||||
should run.with_params([input], 'test', 100).and_return(result)
|
||||
is_expected.to run.with_params([input], 'test', 100).and_return(result)
|
||||
end
|
||||
|
||||
it do
|
||||
|
@ -78,7 +78,7 @@ describe 'postgresql_acls_to_resources_hash', :type => :puppet_function do
|
|||
},
|
||||
}
|
||||
|
||||
should run.with_params([input], 'test', 100).and_return(result)
|
||||
is_expected.to run.with_params([input], 'test', 100).and_return(result)
|
||||
end
|
||||
|
||||
it do
|
||||
|
@ -94,7 +94,7 @@ describe 'postgresql_acls_to_resources_hash', :type => :puppet_function do
|
|||
},
|
||||
}
|
||||
|
||||
should run.with_params([input], 'test', 100).and_return(result)
|
||||
is_expected.to run.with_params([input], 'test', 100).and_return(result)
|
||||
end
|
||||
|
||||
it do
|
||||
|
@ -110,7 +110,7 @@ describe 'postgresql_acls_to_resources_hash', :type => :puppet_function do
|
|||
},
|
||||
}
|
||||
|
||||
should run.with_params([input], 'test', 100).and_return(result)
|
||||
is_expected.to run.with_params([input], 'test', 100).and_return(result)
|
||||
end
|
||||
|
||||
it do
|
||||
|
@ -127,11 +127,11 @@ describe 'postgresql_acls_to_resources_hash', :type => :puppet_function do
|
|||
},
|
||||
}
|
||||
|
||||
should run.with_params([input], 'test', 100).and_return(result)
|
||||
is_expected.to 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({})
|
||||
is_expected.to run.with_params([], 'test', 100).and_return({})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql_escape', :type => :puppet_function do
|
||||
it { should run.with_params('foo').
|
||||
it { is_expected.to run.with_params('foo').
|
||||
and_return('$$foo$$') }
|
||||
end
|
||||
describe 'postgresql_escape', :type => :puppet_function do
|
||||
it { should run.with_params('fo$$o').
|
||||
it { is_expected.to run.with_params('fo$$o').
|
||||
and_return('$ed$fo$$o$ed$') }
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'postgresql_password', :type => :puppet_function do
|
||||
it { should run.with_params('foo', 'bar').
|
||||
it { is_expected.to run.with_params('foo', 'bar').
|
||||
and_return('md596948aad3fcae80c08a35c9b5958cd89') }
|
||||
end
|
||||
|
|
|
@ -22,90 +22,107 @@ describe provider_class do
|
|||
|
||||
describe "simple configuration that should be allowed" do
|
||||
it "should parse a simple ini line" do
|
||||
provider.parse_line("listen_addreses = '*'").should ==
|
||||
expect(provider.parse_line("listen_addreses = '*'")).to eq(
|
||||
{ :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 ==
|
||||
expect(provider.parse_line(" listen_addreses = '*'")).to eq(
|
||||
{ :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 ==
|
||||
expect(provider.parse_line("listen_addreses = '*' # dont mind me")).to eq(
|
||||
{ :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 ==
|
||||
expect(provider.parse_line("# dont mind me")).to eq(
|
||||
{ :line=>"# dont mind me", :record_type=>:comment }
|
||||
)
|
||||
end
|
||||
|
||||
it "should parse a comment (2)" do
|
||||
provider.parse_line(" \t# dont mind me").should ==
|
||||
expect(provider.parse_line(" \t# dont mind me")).to eq(
|
||||
{ :line=>" \t# dont mind me", :record_type=>:comment }
|
||||
)
|
||||
end
|
||||
|
||||
it "should allow includes" do
|
||||
provider.parse_line("include puppetextra").should ==
|
||||
expect(provider.parse_line("include puppetextra")).to eq(
|
||||
{ :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 ==
|
||||
expect(provider.parse_line("wal_keep_segments = 32")).to eq(
|
||||
{ :name=>"wal_keep_segments", :value=>"32", :comment=>nil, :record_type=>:parsed }
|
||||
)
|
||||
end
|
||||
|
||||
it "should allow blanks thorugh " do
|
||||
provider.parse_line("").should ==
|
||||
expect(provider.parse_line("")).to eq(
|
||||
{ :line=>"", :record_type=>:blank }
|
||||
)
|
||||
end
|
||||
|
||||
it "should parse keys with dots " do
|
||||
provider.parse_line("auto_explain.log_min_duration = 1ms").should ==
|
||||
expect(provider.parse_line("auto_explain.log_min_duration = 1ms")).to eq(
|
||||
{ :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 ==
|
||||
expect(provider.to_line({ :line=>"# dont mind me", :record_type=>:comment })).to eq(
|
||||
'# dont mind me'
|
||||
)
|
||||
end
|
||||
|
||||
it "should set blank lines" do
|
||||
provider.to_line({ :line=>"", :record_type=>:blank }).should ==
|
||||
expect(provider.to_line({ :line=>"", :record_type=>:blank })).to eq(
|
||||
''
|
||||
)
|
||||
end
|
||||
|
||||
it "should set simple configuration" do
|
||||
provider.to_line({:name=>"listen_addresses", :value=>"*", :comment=>nil, :record_type=>:parsed }).should ==
|
||||
expect(provider.to_line({:name=>"listen_addresses", :value=>"*", :comment=>nil, :record_type=>:parsed })).to eq(
|
||||
"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 ==
|
||||
expect(provider.to_line({:name => "auto_explain.log_min_duration", :value => '100ms', :comment => nil, :record_type => :parsed })).to eq(
|
||||
"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 ==
|
||||
expect(provider.to_line({:name=>"listen_addresses", :value=>"*", :comment=>'dont mind me', :record_type=>:parsed })).to eq(
|
||||
"listen_addresses = '*' # dont mind me"
|
||||
)
|
||||
end
|
||||
|
||||
it 'should quote includes' do
|
||||
provider.to_line( {:name=>"include", :value=>"puppetextra", :comment=>nil, :record_type=>:parsed }).should ==
|
||||
expect(provider.to_line( {:name=>"include", :value=>"puppetextra", :comment=>nil, :record_type=>:parsed })).to eq(
|
||||
"include 'puppetextra'"
|
||||
)
|
||||
end
|
||||
|
||||
it 'should quote multiple words' do
|
||||
provider.to_line( {:name=>"archive_command", :value=>"rsync up", :comment=>nil, :record_type=>:parsed }).should ==
|
||||
expect(provider.to_line( {:name=>"archive_command", :value=>"rsync up", :comment=>nil, :record_type=>:parsed })).to eq(
|
||||
"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 ==
|
||||
expect(provider.to_line( {:name=>"wal_segments", :value=>"32", :comment=>nil, :record_type=>:parsed })).to eq(
|
||||
"wal_segments = 32"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,17 +34,41 @@ describe Puppet::Type.type(:postgresql_psql), :unless => Puppet.features.microso
|
|||
}.each do |attr, value|
|
||||
context attr do
|
||||
let(:attributes) do { attr => value } end
|
||||
its([attr]) { should == value }
|
||||
|
||||
describe [attr] do
|
||||
subject { super()[attr] }
|
||||
it { is_expected.to eq(value) }
|
||||
end
|
||||
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_falsey }
|
||||
|
||||
describe '[:psql_path]' do
|
||||
subject { super()[:psql_path] }
|
||||
it { is_expected.to eq("psql") }
|
||||
end
|
||||
|
||||
describe '[:psql_user]' do
|
||||
subject { super()[:psql_user] }
|
||||
it { is_expected.to eq("postgres") }
|
||||
end
|
||||
|
||||
describe '[:psql_group]' do
|
||||
subject { super()[:psql_group] }
|
||||
it { is_expected.to eq("postgres") }
|
||||
end
|
||||
|
||||
describe '[:cwd]' do
|
||||
subject { super()[:cwd] }
|
||||
it { is_expected.to eq("/tmp") }
|
||||
end
|
||||
|
||||
describe '#refreshonly?' do
|
||||
subject { super().refreshonly? }
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ describe Puppet::Type.type(:postgresql_conf) do
|
|||
|
||||
describe "namevar validation" do
|
||||
it "should have :name as its namevar" do
|
||||
described_class.key_attributes.should == [:name]
|
||||
expect(described_class.key_attributes).to eq([:name])
|
||||
end
|
||||
it "should not invalid names" do
|
||||
expect { described_class.new(:name => 'foo bar') }.to raise_error(Puppet::Error, /Invalid value/)
|
||||
|
@ -23,13 +23,13 @@ describe Puppet::Type.type(:postgresql_conf) do
|
|||
describe "when validating attributes" do
|
||||
[:name, :provider].each do |param|
|
||||
it "should have a #{param} parameter" do
|
||||
described_class.attrtype(param).should == :param
|
||||
expect(described_class.attrtype(param)).to eq(:param)
|
||||
end
|
||||
end
|
||||
|
||||
[:value, :target].each do |property|
|
||||
it "should have a #{property} property" do
|
||||
described_class.attrtype(property).should == :property
|
||||
expect(described_class.attrtype(property)).to eq(:property)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue