Skip to content

Commit

Permalink
Merge pull request #1530 from puppetlabs/fix-postgresql_default
Browse files Browse the repository at this point in the history
Fix `postgresql::default()` return value for unknown parameters
  • Loading branch information
Ramesh7 authored Oct 12, 2023
2 parents f2f2754 + 4e15857 commit e1c3a24
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
7 changes: 3 additions & 4 deletions functions/default.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ function postgresql::default(
) {
include postgresql::params

#search for the variable name in params first
#then fall back to globals if not found
pick( getvar("postgresql::params::${parameter_name}"),
"postgresql::globals::${parameter_name}")
# Search for the variable name in params.
# params inherits from globals, so it will also catch these variables.
pick(getvar("postgresql::params::${parameter_name}"))
}
34 changes: 34 additions & 0 deletions spec/functions/postgresql_default_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'postgresql::default' do
let(:facts) do
{
'os' => {
'family' => 'Debian',
'name' => 'Debian',
'release' => {
'full' => '11.7',
'major' => '11',
'minor' => '7',
}
}
}
end

let(:pre_condition) do
<<~PP
class { 'postgresql::server':
}
PP
end

# parameter in params.pp only
it { is_expected.to run.with_params('port').and_return(5432) }

# parameter in globals.pp only
it { is_expected.to run.with_params('default_connect_settings').and_return({}) }

it { is_expected.to run.with_params('a_parameter_that_does_not_exist').and_raise_error(Puppet::ParseError, %r{pick\(\): must receive at least one non empty value}) }
end

0 comments on commit e1c3a24

Please sign in to comment.