diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000000..80fcd21df2 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,7 @@ +fixtures: + repositories: + apt: "git://github.com/puppetlabs/puppetlabs-apt.git" + stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" + firewall: "git://github.com/puppetlabs/puppetlabs-firewall.git" + symlinks: + postgresql: "#{source_dir}" diff --git a/.gitignore b/.gitignore index 47a5e3ce00..56863e4c9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .vagrant /postgresql/pkg +# This is a library, so don't pin +Gemfile.lock diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..dd3394d8d2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +language: ruby +bundler_args: --without development +script: "bundle exec rake spec SPEC_OPTS='--format documentation'" +rvm: + - 1.8.7 + - 1.9.3 + - ruby-head +env: + - PUPPET_GEM_VERSION="~> 2.6" + - PUPPET_GEM_VERSION="~> 2.7" + - PUPPET_GEM_VERSION="~> 3.0" +matrix: + allow_failures: + - rvm: ruby-head + exclude: + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 2.7" + - rvm: ruby-head + env: PUPPET_GEM_VERSION="~> 2.7" + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 2.6" + - rvm: ruby-head + env: PUPPET_GEM_VERSION="~> 2.6" +notifications: + email: false diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..0b2db90dc3 --- /dev/null +++ b/Gemfile @@ -0,0 +1,17 @@ +source :rubygems + +group :development, :test do + gem 'rake' + gem 'puppetlabs_spec_helper', :require => false + gem 'vagrant', '~> 1.0.5' + gem 'sahara', '~> 0.0.13' + gem 'puppet-lint', '~> 0.3.2' +end + +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end + +# vim:ft=ruby diff --git a/README.md b/README.md index 2ec2c56ddf..89e4af82be 100644 --- a/README.md +++ b/README.md @@ -158,36 +158,26 @@ If you need to generate a postgres encrypted password, use `postgresql_password` ### Tests -There are two types of tests distributed with the module. The first set is the -“traditional” Puppet manifest-style smoke tests. You can use these to experiment with the module on a virtual machine or other test environment, via `puppet apply`. You should see the following files in the tests directory: - -* init.pp: just installs the postgres client packages - -* server.pp: installs the postgres server packages and starts the service; configures the service to accept connections from remote machines, and sets the password for the postgres database user account to ‘postgres’. - -* postgresql_database.pp: creates a few sample databases with different character sets. Does not create any users for the databases. - -* postgresql_database\_user.pp: creates a few sample users. - -* postgresql_database\_grant.pp: shows an example of granting a privilege on a database to a certain user/role. - -* postgresql_db.pp: creates several test databases, and creates database user accounts with full privileges for each of them. +There are two types of tests distributed with the module. The first set is the “traditional” Puppet manifest-style smoke tests. You can use these to experiment with the module on a virtual machine or other test environment, via `puppet apply`. You should see the following files in the `tests` directory. In addition to these manifest-based smoke tests, there are some ruby rspec tests in the spec directory. These tests run against a VirtualBox VM, so they are actually testing the live application of the module on a real, running system. To do this, you must install and setup an [RVM](http://beginrescueend.com/) with [vagrant](http://vagrantup.com/), [sahara](https://github.com/jedi4ever/sahara), and [rspec](http://rspec.info/): $ curl -L get.rvm.io | bash -s stable $ rvm install 1.9.3 $ rvm use --create 1.9.3@puppet-postgresql - $ gem install vagrant sahara rspec + $ bundle install + +Run the system tests: + + $ rake spec:system -Run the tests: +The system test suite will snapshot the VM and rollback between each test. - $ (cd spec; vagrant up) - $ rspec -f -d -c +We also have some unit tests that utilize rspec-puppet for faster iteration if required: -The test suite will snapshot the VM and rollback between each test. Next, take a look at the manifests used for the automated tests. + $ rake spec - $ cat spec/manifests/test_*.pp +The unit tests are ran in Travis-CI as well, if you want to see the results of your own tests regsiter the service hook through Travis-CI via the accounts section for your Github clone of this project. Implementation --------------- diff --git a/Rakefile b/Rakefile index 3e3e5f4418..a546dd519e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,14 @@ -#require 'puppetlabs_spec_helper/rake_tasks' +require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-lint/tasks/puppet-lint' PuppetLint.configuration.send("disable_80chars") + +RSpec::Core::RakeTask.new(:system_test) do |c| + c.pattern = "spec/system/**/*_spec.rb" +end + + +namespace :spec do + desc 'Run system tests' + task :system => :system_test +end diff --git a/lib/facter/postgres_default_version.rb b/lib/facter/postgres_default_version.rb index e7b53e37a2..ca67c17f24 100644 --- a/lib/facter/postgres_default_version.rb +++ b/lib/facter/postgres_default_version.rb @@ -63,11 +63,9 @@ def get_redhatfamily_postgres_version # TODO: not sure if this is really a great idea, but elsewhere in the code # it is useful to be able to distinguish between the case where the fact # does not exist at all (e.g., if pluginsync is not enabled), and the case - # where the fact is not known for the OS in question. It might be better - # to use a shorter sentinel value here and then check for it elsewhere, - # e.g. in the same place we're checking for nil and warning about pluginsync. + # where the fact is not known for the OS in question. if result == nil - result = "Unsupported OS! Please check `postgres_default_version` fact." + result = 'unknown' end result end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000000..758ce62c25 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,15 @@ +require 'puppetlabs_spec_helper/module_spec_helper' + +RSpec.configure do |config| + config.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 +end diff --git a/spec/support/shared_contexts/pg_vm_context.rb b/spec/support/shared_contexts/pg_vm_context.rb index 2db8aaf28a..d5a95caed7 100644 --- a/spec/support/shared_contexts/pg_vm_context.rb +++ b/spec/support/shared_contexts/pg_vm_context.rb @@ -51,4 +51,4 @@ end end -end \ No newline at end of file +end diff --git a/spec/support/vagrant_common.rb b/spec/support/vagrant_common.rb index eba4e05606..5c60954a80 100644 --- a/spec/support/vagrant_common.rb +++ b/spec/support/vagrant_common.rb @@ -4,11 +4,11 @@ def apply_common_vagrant_config(config) # Share the various required modules # TODO: it would be better to install this via the puppet module tool - config.vm.share_folder "puppetlabs-stdlib-module", "/usr/share/puppet/modules/stdlib", "../../../../puppetlabs-stdlib" - config.vm.share_folder "puppetlabs-apt-module", "/usr/share/puppet/modules/apt", "../../../../puppetlabs-apt" + config.vm.share_folder "puppetlabs-stdlib-module", "/usr/share/puppet/modules/stdlib", "../../../../../puppetlabs-stdlib" + config.vm.share_folder "puppetlabs-apt-module", "/usr/share/puppet/modules/apt", "../../../../../puppetlabs-apt" # Share the postgressql module - config.vm.share_folder "puppet-postgresql-module", "/usr/share/puppet/modules/postgresql", "../../.." + config.vm.share_folder "puppet-postgresql-module", "/usr/share/puppet/modules/postgresql", "../../../.." # Share the module of test classes config.vm.share_folder "puppet-postgresql-tests", "/usr/share/puppet/modules/postgresql_tests", "../../test_module" diff --git a/spec/README.md b/spec/system/README.md similarity index 100% rename from spec/README.md rename to spec/system/README.md diff --git a/spec/base.pp b/spec/system/base.pp similarity index 100% rename from spec/base.pp rename to spec/system/base.pp diff --git a/spec/distros/centos6_64/Vagrantfile b/spec/system/distros/centos6_64/Vagrantfile similarity index 74% rename from spec/distros/centos6_64/Vagrantfile rename to spec/system/distros/centos6_64/Vagrantfile index 3e747c64f2..53f7929b19 100644 --- a/spec/distros/centos6_64/Vagrantfile +++ b/spec/system/distros/centos6_64/Vagrantfile @@ -1,4 +1,4 @@ -require File.expand_path(File.join(__FILE__, '../../../support/vagrant_common')) +require File.expand_path(File.join(__FILE__, '../../../../support/vagrant_common')) Vagrant::Config.run do |config| @@ -9,4 +9,4 @@ Vagrant::Config.run do |config| apply_common_vagrant_config(config) -end \ No newline at end of file +end diff --git a/spec/distros/centos6_64/non_default_pg_spec.rb b/spec/system/distros/centos6_64/non_default_pg_spec.rb similarity index 98% rename from spec/distros/centos6_64/non_default_pg_spec.rb rename to spec/system/distros/centos6_64/non_default_pg_spec.rb index b4334f1842..89e841e4e6 100644 --- a/spec/distros/centos6_64/non_default_pg_spec.rb +++ b/spec/system/distros/centos6_64/non_default_pg_spec.rb @@ -4,4 +4,4 @@ let(:vagrant_dir) { File.dirname(__FILE__) } let(:vm) { :centos6 } it_behaves_like :non_default_postgres -end \ No newline at end of file +end diff --git a/spec/distros/centos6_64/system_default_pg_spec.rb b/spec/system/distros/centos6_64/system_default_pg_spec.rb similarity index 98% rename from spec/distros/centos6_64/system_default_pg_spec.rb rename to spec/system/distros/centos6_64/system_default_pg_spec.rb index d9dbac9391..fef5b804df 100644 --- a/spec/distros/centos6_64/system_default_pg_spec.rb +++ b/spec/system/distros/centos6_64/system_default_pg_spec.rb @@ -5,4 +5,4 @@ let(:vm) { :centos6 } let(:service_name) { 'postgresql' } it_behaves_like :system_default_postgres -end \ No newline at end of file +end diff --git a/spec/distros/ubuntu_lucid_64/Vagrantfile b/spec/system/distros/ubuntu_lucid_64/Vagrantfile similarity index 74% rename from spec/distros/ubuntu_lucid_64/Vagrantfile rename to spec/system/distros/ubuntu_lucid_64/Vagrantfile index fe84e1c8fa..172acb5529 100644 --- a/spec/distros/ubuntu_lucid_64/Vagrantfile +++ b/spec/system/distros/ubuntu_lucid_64/Vagrantfile @@ -1,4 +1,4 @@ -require File.expand_path(File.join(__FILE__, '../../../support/vagrant_common')) +require File.expand_path(File.join(__FILE__, '../../../../support/vagrant_common')) Vagrant::Config.run do |config| @@ -10,4 +10,4 @@ Vagrant::Config.run do |config| apply_common_vagrant_config(config) -end \ No newline at end of file +end diff --git a/spec/distros/ubuntu_lucid_64/non_default_pg_spec.rb b/spec/system/distros/ubuntu_lucid_64/non_default_pg_spec.rb similarity index 98% rename from spec/distros/ubuntu_lucid_64/non_default_pg_spec.rb rename to spec/system/distros/ubuntu_lucid_64/non_default_pg_spec.rb index 6e228e7c60..ca54ba0591 100644 --- a/spec/distros/ubuntu_lucid_64/non_default_pg_spec.rb +++ b/spec/system/distros/ubuntu_lucid_64/non_default_pg_spec.rb @@ -4,4 +4,4 @@ let(:vagrant_dir) { File.dirname(__FILE__) } let(:vm) { :lucid } it_behaves_like :non_default_postgres -end \ No newline at end of file +end diff --git a/spec/distros/ubuntu_lucid_64/system_default_pg_spec.rb b/spec/system/distros/ubuntu_lucid_64/system_default_pg_spec.rb similarity index 98% rename from spec/distros/ubuntu_lucid_64/system_default_pg_spec.rb rename to spec/system/distros/ubuntu_lucid_64/system_default_pg_spec.rb index a7d9a90b20..4d2bd12db6 100644 --- a/spec/distros/ubuntu_lucid_64/system_default_pg_spec.rb +++ b/spec/system/distros/ubuntu_lucid_64/system_default_pg_spec.rb @@ -5,4 +5,4 @@ let(:vm) { :lucid } let(:service_name) { 'postgresql-8.4' } it_behaves_like :system_default_postgres -end \ No newline at end of file +end diff --git a/spec/test_module/manifests/non_default/test_db.pp b/spec/system/test_module/manifests/non_default/test_db.pp similarity index 100% rename from spec/test_module/manifests/non_default/test_db.pp rename to spec/system/test_module/manifests/non_default/test_db.pp diff --git a/spec/test_module/manifests/non_default/test_install.pp b/spec/system/test_module/manifests/non_default/test_install.pp similarity index 100% rename from spec/test_module/manifests/non_default/test_install.pp rename to spec/system/test_module/manifests/non_default/test_install.pp diff --git a/spec/test_module/manifests/system_default/test_db.pp b/spec/system/test_module/manifests/system_default/test_db.pp similarity index 100% rename from spec/test_module/manifests/system_default/test_db.pp rename to spec/system/test_module/manifests/system_default/test_db.pp diff --git a/spec/test_module/manifests/system_default/test_grant_create.pp b/spec/system/test_module/manifests/system_default/test_grant_create.pp similarity index 100% rename from spec/test_module/manifests/system_default/test_grant_create.pp rename to spec/system/test_module/manifests/system_default/test_grant_create.pp diff --git a/spec/test_module/manifests/system_default/test_initdb.pp b/spec/system/test_module/manifests/system_default/test_initdb.pp similarity index 100% rename from spec/test_module/manifests/system_default/test_initdb.pp rename to spec/system/test_module/manifests/system_default/test_initdb.pp diff --git a/spec/test_module/manifests/system_default/test_pgconf_include.pp b/spec/system/test_module/manifests/system_default/test_pgconf_include.pp similarity index 100% rename from spec/test_module/manifests/system_default/test_pgconf_include.pp rename to spec/system/test_module/manifests/system_default/test_pgconf_include.pp diff --git a/spec/test_module/manifests/system_default/test_pgconf_include_cleanup.pp b/spec/system/test_module/manifests/system_default/test_pgconf_include_cleanup.pp similarity index 100% rename from spec/test_module/manifests/system_default/test_pgconf_include_cleanup.pp rename to spec/system/test_module/manifests/system_default/test_pgconf_include_cleanup.pp diff --git a/spec/test_module/manifests/system_default/test_psql.pp b/spec/system/test_module/manifests/system_default/test_psql.pp similarity index 100% rename from spec/test_module/manifests/system_default/test_psql.pp rename to spec/system/test_module/manifests/system_default/test_psql.pp diff --git a/spec/test_module/manifests/system_default/test_ruby_psql.pp b/spec/system/test_module/manifests/system_default/test_ruby_psql.pp similarity index 100% rename from spec/test_module/manifests/system_default/test_ruby_psql.pp rename to spec/system/test_module/manifests/system_default/test_ruby_psql.pp diff --git a/spec/test_module/manifests/system_default/test_tablespace.pp b/spec/system/test_module/manifests/system_default/test_tablespace.pp similarity index 100% rename from spec/test_module/manifests/system_default/test_tablespace.pp rename to spec/system/test_module/manifests/system_default/test_tablespace.pp diff --git a/spec/test_module/manifests/system_default/test_user.pp b/spec/system/test_module/manifests/system_default/test_user.pp similarity index 100% rename from spec/test_module/manifests/system_default/test_user.pp rename to spec/system/test_module/manifests/system_default/test_user.pp diff --git a/spec/unit/classes/client_spec.rb b/spec/unit/classes/client_spec.rb new file mode 100644 index 0000000000..6da32b3a05 --- /dev/null +++ b/spec/unit/classes/client_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe 'postgresql::client', :type => :class do + let :facts do + { + :postgres_default_version => '8.4', + :osfamily => 'Debian', + } + end + it { should include_class("postgresql::client") } +end diff --git a/spec/unit/classes/devel_spec.rb b/spec/unit/classes/devel_spec.rb new file mode 100644 index 0000000000..c8436daaae --- /dev/null +++ b/spec/unit/classes/devel_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe 'postgresql::devel', :type => :class do + let :facts do + { + :postgres_default_version => '8.4', + :osfamily => 'Debian', + } + end + it { should include_class("postgresql::devel") } +end diff --git a/spec/unit/classes/init_spec.rb b/spec/unit/classes/init_spec.rb new file mode 100644 index 0000000000..4138420e2e --- /dev/null +++ b/spec/unit/classes/init_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe 'postgresql', :type => :class do + let :facts do + { + :postgres_default_version => '8.4', + :osfamily => 'Debian', + } + end + it { should include_class("postgresql") } +end diff --git a/spec/unit/classes/params_spec.rb b/spec/unit/classes/params_spec.rb new file mode 100644 index 0000000000..56b1f90fcb --- /dev/null +++ b/spec/unit/classes/params_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe 'postgresql::params', :type => :class do + let :facts do + { + :postgres_default_version => '8.4', + :osfamily => 'Debian', + } + end + it { should include_class("postgresql::params") } +end diff --git a/spec/unit/classes/server_spec.rb b/spec/unit/classes/server_spec.rb new file mode 100644 index 0000000000..1bb9fc057b --- /dev/null +++ b/spec/unit/classes/server_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe 'postgresql::server', :type => :class do + let :facts do + { + :postgres_default_version => '8.4', + :osfamily => 'Debian', + } + end + it { should include_class("postgresql::server") } +end diff --git a/spec/unit/defines/database_grant_spec.rb b/spec/unit/defines/database_grant_spec.rb new file mode 100644 index 0000000000..8cbb3fb269 --- /dev/null +++ b/spec/unit/defines/database_grant_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe 'postgresql::database_grant', :type => :define do + let :facts do + { + :postgres_default_version => '8.4', + :osfamily => 'Debian', + } + end + let :title do + 'test' + end + let :params do + { + :privilege => 'ALL', + :db => 'test', + :role => 'test', + } + end + it { should include_class("postgresql::params") } +end diff --git a/spec/unit/defines/database_spec.rb b/spec/unit/defines/database_spec.rb new file mode 100644 index 0000000000..a2ba81be59 --- /dev/null +++ b/spec/unit/defines/database_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe 'postgresql::database', :type => :define do + let :facts do + { + :postgres_default_version => '8.4', + :osfamily => 'Debian', + } + end + let :title do + 'test' + end + it { should include_class("postgresql::params") } +end diff --git a/spec/unit/defines/database_user_spec.rb b/spec/unit/defines/database_user_spec.rb new file mode 100644 index 0000000000..998b5db32f --- /dev/null +++ b/spec/unit/defines/database_user_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe 'postgresql::database_user', :type => :define do + let :facts do + { + :postgres_default_version => '8.4', + :osfamily => 'Debian', + } + end + let :title do + 'test' + end + let :params do + { + :password_hash => 'test', + } + end + it { should include_class("postgresql::params") } +end diff --git a/spec/unit/defines/db_spec.rb b/spec/unit/defines/db_spec.rb new file mode 100644 index 0000000000..077a72016f --- /dev/null +++ b/spec/unit/defines/db_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe 'postgresql::db', :type => :define do + let :facts do + { + :postgres_default_version => '8.4', + :osfamily => 'Debian', + } + end + let :title do + 'test' + end + let :params do + { + :user => 'test', + :password => 'test', + } + end + it { should include_class("postgresql::params") } +end diff --git a/spec/unit/defines/psql_spec.rb b/spec/unit/defines/psql_spec.rb new file mode 100644 index 0000000000..3c21b11842 --- /dev/null +++ b/spec/unit/defines/psql_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe 'postgresql::psql', :type => :define do + let :facts do + { + :postgres_default_version => '8.4', + :osfamily => 'Debian', + } + end + let :title do + 'test' + end + let :params do + { + :db => 'test', + :unless => 'test', + } + end + it { should include_class("postgresql::params") } +end diff --git a/spec/unit/defines/role_spec.pp b/spec/unit/defines/role_spec.pp new file mode 100644 index 0000000000..e531390d31 --- /dev/null +++ b/spec/unit/defines/role_spec.pp @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe 'postgresql::role', :type => :define do + let :facts do + { + :postgres_default_version => '8.4', + :osfamily => 'Debian', + } + end + let :title do + 'test' + end + it { should include_class("postgresql::params") } +end diff --git a/spec/unit/defines/tablespace_spec.pp b/spec/unit/defines/tablespace_spec.pp new file mode 100644 index 0000000000..5a58df560a --- /dev/null +++ b/spec/unit/defines/tablespace_spec.pp @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe 'postgresql::tablespace', :type => :define do + let :facts do + { + :postgres_default_version => '8.4', + :osfamily => 'Debian', + } + end + let :title do + 'test' + end + it { should include_class("postgresql::params") } +end diff --git a/spec/unit/defines/validate_db_connection_spec.rb b/spec/unit/defines/validate_db_connection_spec.rb new file mode 100644 index 0000000000..76bcfcbc5f --- /dev/null +++ b/spec/unit/defines/validate_db_connection_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe 'postgresql::validate_db_connection', :type => :define do + let :facts do + { + :postgres_default_version => '8.4', + :osfamily => 'Debian', + } + end + let :title do + 'test' + end + let :params do + { + :database_host => 'test', + :database_name => 'test', + :database_password => 'test', + :database_username => 'test', + } + end + it { should include_class("postgresql::params") } +end diff --git a/spec/unit/facts/postgres_default_version_spec.rb b/spec/unit/facts/postgres_default_version_spec.rb new file mode 100644 index 0000000000..5ad5f7b14d --- /dev/null +++ b/spec/unit/facts/postgres_default_version_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe 'postgres_default_version', :type => :fact do + it 'should handle redhat 6.0' do + Facter.fact(:osfamily).stubs(:value).returns 'RedHat' + Facter.fact(:operatingsystemrelease).stubs(:value).returns '6.0' + Facter.fact(:postgres_default_version).value.should == '8.4' + end + + it 'should return unknown if osfamily is unknown' do + Facter.fact(:osfamily).expects(:value).returns 'test' + Facter.fact(:postgres_default_version).value.should eq 'unknown' + end +end diff --git a/spec/unit/functions/postgresql_password_spec.rb b/spec/unit/functions/postgresql_password_spec.rb new file mode 100644 index 0000000000..0d043f8734 --- /dev/null +++ b/spec/unit/functions/postgresql_password_spec.rb @@ -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