non_default_postgres.rb 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. require 'support/postgres_test_utils'
  2. require 'support/shared_contexts/pg_vm_context'
  3. shared_examples :non_default_postgres do
  4. include PostgresTestUtils
  5. include_context :pg_vm_context
  6. # this method is required by the pg_vm shared context
  7. def install_postgres; end
  8. describe 'postgresql global config' do
  9. it 'with version and manage_package_repo set, we should be able to idempotently create a db that we can connect to' do
  10. manifest = <<-EOS
  11. # Configure version and manage_package_repo globally, install postgres
  12. # and then try to install a new database.
  13. class { "postgresql":
  14. version => "9.2",
  15. manage_package_repo => true,
  16. package_source => "yum.postgresql.org",
  17. }->
  18. class { "postgresql::server": }->
  19. postgresql::db { "postgresql_test_db":
  20. user => "foo1",
  21. password => "foo1",
  22. }
  23. EOS
  24. begin
  25. # Run once to check for crashes
  26. sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{manifest}'; [ $? = 2 ]")
  27. # Run again to check for idempotence
  28. sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{manifest}'")
  29. # Check that the database name is present
  30. sudo_psql_and_log(vm, 'postgresql_test_db --command="select datname from pg_database limit 1"')
  31. ensure
  32. sudo_psql_and_log(vm, '--command="drop database postgresql_test_db" postgres')
  33. end
  34. end
  35. it 'with locale and charset, the postgres database should reflect that locale' do
  36. pending('no support for initdb with lucid', :if => vm == :lucid)
  37. pending('no support for locale parameter with centos 5', :if => vm == :centos5)
  38. manifest = <<-EOS
  39. # Set global locale and charset option, and try installing postgres
  40. class { 'postgresql':
  41. locale => 'en_NG',
  42. charset => 'UTF8',
  43. }->
  44. class { 'postgresql::server': }
  45. EOS
  46. # Run once to check for crashes
  47. sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{manifest}'; [ $? = 2 ]")
  48. # Run again to check for idempotence
  49. sudo_and_log(vm, "puppet apply --detailed-exitcodes -e '#{manifest}'")
  50. # Use the command line to create the database, instead of the puppet way
  51. # to bypass any puppet effects and make sure the default works _always_.
  52. sudo_and_log(vm, "su postgres -c 'createdb test1'")
  53. # Check locale of database 'postgres' to ensure initdb did the correct
  54. # thing.
  55. sudo_and_log(vm, 'su postgres -c \'psql -c "show lc_ctype" test1\'')
  56. sudo_and_log(vm, 'su postgres -c \'psql -c "show lc_ctype" test1\' | grep en_NG')
  57. sudo_and_log(vm, 'su postgres -c \'psql -c "show lc_collate" test1\' | grep en_NG')
  58. end
  59. end
  60. end