From 47bc3423f6251a2a1c28cc03ebc3fab2cb31c7a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Can=C3=A9vet?= Date: Tue, 8 Apr 2014 16:38:31 +0200 Subject: [PATCH 1/2] Add strict_variables support in unit tests --- .travis.yml | 1 + spec/spec_helper.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index fb14e76..762b997 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ env: - PUPPET_GEM_VERSION="~> 2.7.0" - PUPPET_GEM_VERSION="~> 3.2.0" - PUPPET_GEM_VERSION="~> 3.4.0" + - PUPPET_GEM_VERSION="~> 3.5.0.rc3" STRICT_VARIABLES="yes" matrix: fast_finish: true exclude: diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b4c44aa..1cc1fce 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,6 +16,10 @@ RSpec.configure do |c| # Store any environment variables away to be restored later @old_env = {} ENV.each_key {|k| @old_env[k] = ENV[k]} + + if ENV['STRICT_VARIABLES'] == 'yes' + Puppet.settings[:strict_variables]=true + end end c.after :each do From 0b7bb333d80d600bcf72bed9c9ffb9f304b1966b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Can=C3=A9vet?= Date: Tue, 8 Apr 2014 16:40:49 +0200 Subject: [PATCH 2/2] Fix strict_variables issues --- manifests/globals.pp | 1 + manifests/params.pp | 4 +-- manifests/repo/apt_postgresql_org.pp | 1 + spec/unit/classes/globals_spec.rb | 1 + spec/unit/classes/repo_spec.rb | 1 + spec/unit/classes/server/contrib_spec.rb | 2 ++ spec/unit/classes/server/initdb_spec.rb | 6 ++++ spec/unit/classes/server/plperl_spec.rb | 2 ++ spec/unit/classes/server/postgis_spec.rb | 2 ++ spec/unit/classes/server_spec.rb | 2 ++ spec/unit/defines/server/config_entry_spec.rb | 8 +++++ .../defines/server/database_grant_spec.rb | 8 +++++ spec/unit/defines/server/database_spec.rb | 9 +++++ spec/unit/defines/server/db_spec.rb | 12 +++++++ spec/unit/defines/server/grant_spec.rb | 8 +++++ spec/unit/defines/server/pg_hba_rule_spec.rb | 33 +++++++++++++++++++ spec/unit/defines/server/role_spec.rb | 8 +++++ spec/unit/defines/server/table_grant_spec.rb | 8 +++++ spec/unit/defines/server/tablespace_spec.rb | 8 +++++ 19 files changed, 122 insertions(+), 2 deletions(-) diff --git a/manifests/globals.pp b/manifests/globals.pp index 852dda1..72bb79f 100644 --- a/manifests/globals.pp +++ b/manifests/globals.pp @@ -10,6 +10,7 @@ class postgresql::globals ( $java_package_name = undef, $plperl_package_name = undef, $python_package_name = undef, + $postgis_package_name = undef, $service_name = undef, $service_provider = undef, diff --git a/manifests/params.pp b/manifests/params.pp index f83cfa7..aaaf190 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -21,6 +21,8 @@ class postgresql::params inherits postgresql::globals { $group = pick($group, 'postgres') $needs_initdb = pick($needs_initdb, true) $firewall_supported = pick($firewall_supported, true) + $version_parts = split($version, '[.]') + $package_version = "${version_parts[0]}${version_parts[1]}" if $version == $default_version { $client_package_name = pick($client_package_name, 'postgresql') @@ -37,8 +39,6 @@ class postgresql::params inherits postgresql::globals { } $confdir = pick($confdir, $datadir) } else { - $version_parts = split($version, '[.]') - $package_version = "${version_parts[0]}${version_parts[1]}" $client_package_name = pick($client_package_name, "postgresql${package_version}") $server_package_name = pick($server_package_name, "postgresql${package_version}-server") $contrib_package_name = pick($contrib_package_name,"postgresql${package_version}-contrib") diff --git a/manifests/repo/apt_postgresql_org.pp b/manifests/repo/apt_postgresql_org.pp index 610eb47..25cb148 100644 --- a/manifests/repo/apt_postgresql_org.pp +++ b/manifests/repo/apt_postgresql_org.pp @@ -1,5 +1,6 @@ # PRIVATE CLASS: do not use directly class postgresql::repo::apt_postgresql_org inherits postgresql::repo { +include ::apt if($ensure == 'present' or $ensure == true) { # Here we have tried to replicate the instructions on the PostgreSQL site: # diff --git a/spec/unit/classes/globals_spec.rb b/spec/unit/classes/globals_spec.rb index f8feb2f..315a349 100644 --- a/spec/unit/classes/globals_spec.rb +++ b/spec/unit/classes/globals_spec.rb @@ -7,6 +7,7 @@ describe 'postgresql::globals', :type => :class do :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', :lsbdistid => 'Debian', + :lsbdistcodename => 'squeeze', } end diff --git a/spec/unit/classes/repo_spec.rb b/spec/unit/classes/repo_spec.rb index e7e286f..f31d468 100644 --- a/spec/unit/classes/repo_spec.rb +++ b/spec/unit/classes/repo_spec.rb @@ -7,6 +7,7 @@ describe 'postgresql::repo', :type => :class do :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', :lsbdistid => 'Debian', + :lsbdistcodename => 'squeeze', } end diff --git a/spec/unit/classes/server/contrib_spec.rb b/spec/unit/classes/server/contrib_spec.rb index 9fbab06..a22a3d0 100644 --- a/spec/unit/classes/server/contrib_spec.rb +++ b/spec/unit/classes/server/contrib_spec.rb @@ -12,6 +12,8 @@ describe 'postgresql::server::contrib', :type => :class do :operatingsystemrelease => '6.0', :kernel => 'Linux', :concat_basedir => tmpfilename('contrib'), + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end diff --git a/spec/unit/classes/server/initdb_spec.rb b/spec/unit/classes/server/initdb_spec.rb index bcf2dbe..605c518 100644 --- a/spec/unit/classes/server/initdb_spec.rb +++ b/spec/unit/classes/server/initdb_spec.rb @@ -11,6 +11,9 @@ describe 'postgresql::server::initdb', :type => :class do :operatingsystem => 'CentOS', :operatingsystemrelease => '6.0', :concat_basedir => tmpfilename('server'), + :kernel => 'Linux', + :id => 'root', + :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') } @@ -21,6 +24,9 @@ describe 'postgresql::server::initdb', :type => :class do :osfamily => 'RedHat', :operatingsystem => 'Amazon', :concat_basedir => tmpfilename('server'), + :kernel => 'Linux', + :id => 'root', + :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') } diff --git a/spec/unit/classes/server/plperl_spec.rb b/spec/unit/classes/server/plperl_spec.rb index 785ed9a..a0c914e 100644 --- a/spec/unit/classes/server/plperl_spec.rb +++ b/spec/unit/classes/server/plperl_spec.rb @@ -8,6 +8,8 @@ describe 'postgresql::server::plperl', :type => :class do :operatingsystemrelease => '6.0', :kernel => 'Linux', :concat_basedir => tmpfilename('plperl'), + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end diff --git a/spec/unit/classes/server/postgis_spec.rb b/spec/unit/classes/server/postgis_spec.rb index 5b35f69..6636bf2 100644 --- a/spec/unit/classes/server/postgis_spec.rb +++ b/spec/unit/classes/server/postgis_spec.rb @@ -12,6 +12,8 @@ describe 'postgresql::server::postgis', :type => :class do :operatingsystemrelease => '6.0', :kernel => 'Linux', :concat_basedir => tmpfilename('postgis'), + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end diff --git a/spec/unit/classes/server_spec.rb b/spec/unit/classes/server_spec.rb index 203eecb..c7a6b6d 100644 --- a/spec/unit/classes/server_spec.rb +++ b/spec/unit/classes/server_spec.rb @@ -8,6 +8,8 @@ describe 'postgresql::server', :type => :class do :operatingsystemrelease => '6.0', :concat_basedir => tmpfilename('server'), :kernel => 'Linux', + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end diff --git a/spec/unit/defines/server/config_entry_spec.rb b/spec/unit/defines/server/config_entry_spec.rb index 4c25c67..e7c59fd 100644 --- a/spec/unit/defines/server/config_entry_spec.rb +++ b/spec/unit/defines/server/config_entry_spec.rb @@ -6,6 +6,10 @@ describe 'postgresql::server::config_entry', :type => :define 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 @@ -16,6 +20,10 @@ describe 'postgresql::server::config_entry', :type => :define do end context "syntax check" do + let :pre_condition do + "class {'postgresql::server':}" + end + let(:params) { { :ensure => 'present'} } it { should contain_postgresql__server__config_entry('config_entry') } end diff --git a/spec/unit/defines/server/database_grant_spec.rb b/spec/unit/defines/server/database_grant_spec.rb index 2e481df..cf18469 100644 --- a/spec/unit/defines/server/database_grant_spec.rb +++ b/spec/unit/defines/server/database_grant_spec.rb @@ -6,6 +6,10 @@ describe 'postgresql::server::database_grant', :type => :define do :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', + :kernel => 'Linux', + :concat_basedir => tmpfilename('contrib'), + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end @@ -21,6 +25,10 @@ describe 'postgresql::server::database_grant', :type => :define do } end + let :pre_condition do + "class {'postgresql::server':}" + end + it { should contain_postgresql__server__database_grant('test') } it { should contain_postgresql__server__grant('database:test') } end diff --git a/spec/unit/defines/server/database_spec.rb b/spec/unit/defines/server/database_spec.rb index a703827..a3d1ace 100644 --- a/spec/unit/defines/server/database_spec.rb +++ b/spec/unit/defines/server/database_spec.rb @@ -6,11 +6,20 @@ describe 'postgresql::server::database', :type => :define do :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', + :kernel => 'Linux', + :concat_basedir => tmpfilename('contrib'), + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :title do 'test' end + + let :pre_condition do + "class {'postgresql::server':}" + end + it { should contain_postgresql__server__database('test') } it { should contain_postgresql_psql("Check for existence of db 'test'") } end diff --git a/spec/unit/defines/server/db_spec.rb b/spec/unit/defines/server/db_spec.rb index 291d50b..157de10 100644 --- a/spec/unit/defines/server/db_spec.rb +++ b/spec/unit/defines/server/db_spec.rb @@ -6,6 +6,10 @@ describe 'postgresql::server::db', :type => :define do :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', + :kernel => 'Linux', + :concat_basedir => tmpfilename('contrib'), + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end @@ -23,6 +27,10 @@ describe 'postgresql::server::db', :type => :define do } end + let :pre_condition 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') } @@ -41,6 +49,10 @@ describe 'postgresql::server::db', :type => :define do } end + let :pre_condition do + "class {'postgresql::server':}" + end + it { should contain_postgresql__server__database('testtest') } end end diff --git a/spec/unit/defines/server/grant_spec.rb b/spec/unit/defines/server/grant_spec.rb index 43eeb8c..c020a69 100644 --- a/spec/unit/defines/server/grant_spec.rb +++ b/spec/unit/defines/server/grant_spec.rb @@ -6,6 +6,10 @@ describe 'postgresql::server::grant', :type => :define do :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', + :kernel => 'Linux', + :concat_basedir => tmpfilename('contrib'), + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end @@ -20,5 +24,9 @@ describe 'postgresql::server::grant', :type => :define do } end + let :pre_condition do + "class {'postgresql::server':}" + end + it { should contain_postgresql__server__grant('test') } end diff --git a/spec/unit/defines/server/pg_hba_rule_spec.rb b/spec/unit/defines/server/pg_hba_rule_spec.rb index a4f6410..abe4de0 100644 --- a/spec/unit/defines/server/pg_hba_rule_spec.rb +++ b/spec/unit/defines/server/pg_hba_rule_spec.rb @@ -6,7 +6,10 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', + :kernel => 'Linux', :concat_basedir => tmpfilename('pg_hba'), + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let :title do @@ -17,6 +20,12 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do end context 'test template 1' do + let :pre_condition do + <<-EOS + class { 'postgresql::server': } + EOS + end + let :params do { :type => 'host', @@ -35,6 +44,12 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do end context 'test template 2' do + let :pre_condition do + <<-EOS + class { 'postgresql::server': } + EOS + end + let :params do { :type => 'local', @@ -52,6 +67,12 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do end context 'test template 3' do + let :pre_condition do + <<-EOS + class { 'postgresql::server': } + EOS + end + let :params do { :type => 'host', @@ -72,6 +93,12 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do context 'validation' do context 'validate type test 1' do + let :pre_condition do + <<-EOS + class { 'postgresql::server': } + EOS + end + let :params do { :type => 'invalid', @@ -89,6 +116,12 @@ describe 'postgresql::server::pg_hba_rule', :type => :define do end context 'validate auth_method' do + let :pre_condition do + <<-EOS + class { 'postgresql::server': } + EOS + end + let :params do { :type => 'local', diff --git a/spec/unit/defines/server/role_spec.rb b/spec/unit/defines/server/role_spec.rb index a50ca14..18ebb84 100644 --- a/spec/unit/defines/server/role_spec.rb +++ b/spec/unit/defines/server/role_spec.rb @@ -6,6 +6,10 @@ describe 'postgresql::server::role', :type => :define do :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', + :kernel => 'Linux', + :concat_basedir => tmpfilename('contrib'), + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end @@ -19,5 +23,9 @@ describe 'postgresql::server::role', :type => :define do } end + let :pre_condition do + "class {'postgresql::server':}" + end + it { should contain_postgresql__server__role('test') } end diff --git a/spec/unit/defines/server/table_grant_spec.rb b/spec/unit/defines/server/table_grant_spec.rb index 15136a7..0ba0277 100644 --- a/spec/unit/defines/server/table_grant_spec.rb +++ b/spec/unit/defines/server/table_grant_spec.rb @@ -6,6 +6,10 @@ describe 'postgresql::server::table_grant', :type => :define do :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', + :kernel => 'Linux', + :concat_basedir => tmpfilename('table_grant'), + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end @@ -22,6 +26,10 @@ describe 'postgresql::server::table_grant', :type => :define do } end + let :pre_condition do + "class {'postgresql::server':}" + end + it { should contain_postgresql__server__table_grant('test') } it { should contain_postgresql__server__grant('table:test') } end diff --git a/spec/unit/defines/server/tablespace_spec.rb b/spec/unit/defines/server/tablespace_spec.rb index eb29f1e..848f461 100644 --- a/spec/unit/defines/server/tablespace_spec.rb +++ b/spec/unit/defines/server/tablespace_spec.rb @@ -6,6 +6,10 @@ describe 'postgresql::server::tablespace', :type => :define do :osfamily => 'Debian', :operatingsystem => 'Debian', :operatingsystemrelease => '6.0', + :kernel => 'Linux', + :concat_basedir => tmpfilename('tablespace'), + :id => 'root', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end @@ -19,5 +23,9 @@ describe 'postgresql::server::tablespace', :type => :define do } end + let :pre_condition do + "class {'postgresql::server':}" + end + it { should contain_postgresql__server__tablespace('test') } end