Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -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}"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.vagrant
/postgresql/pkg
# This is a library, so don't pin
Gemfile.lock
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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
30 changes: 10 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------
Expand Down
12 changes: 11 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -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
6 changes: 2 additions & 4 deletions lib/facter/postgres_default_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion spec/support/shared_contexts/pg_vm_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
end
end

end
end
6 changes: 3 additions & 3 deletions spec/support/vagrant_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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|

Expand All @@ -9,4 +9,4 @@ Vagrant::Config.run do |config|

apply_common_vagrant_config(config)

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
let(:vagrant_dir) { File.dirname(__FILE__) }
let(:vm) { :centos6 }
it_behaves_like :non_default_postgres
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
let(:vm) { :centos6 }
let(:service_name) { 'postgresql' }
it_behaves_like :system_default_postgres
end
end
Original file line number Diff line number Diff line change
@@ -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|

Expand All @@ -10,4 +10,4 @@ Vagrant::Config.run do |config|

apply_common_vagrant_config(config)

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
let(:vagrant_dir) { File.dirname(__FILE__) }
let(:vm) { :lucid }
it_behaves_like :non_default_postgres
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
let(:vm) { :lucid }
let(:service_name) { 'postgresql-8.4' }
it_behaves_like :system_default_postgres
end
end
11 changes: 11 additions & 0 deletions spec/unit/classes/client_spec.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions spec/unit/classes/devel_spec.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions spec/unit/classes/init_spec.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions spec/unit/classes/params_spec.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions spec/unit/classes/server_spec.rb
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions spec/unit/defines/database_grant_spec.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions spec/unit/defines/database_spec.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions spec/unit/defines/database_user_spec.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions spec/unit/defines/db_spec.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions spec/unit/defines/psql_spec.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions spec/unit/defines/role_spec.pp
Original file line number Diff line number Diff line change
@@ -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
Loading