Skip to content

Commit 6cb50cb

Browse files
committed
Fix postgresql::default() return value for unknown parameters
When calling `postgresql::default()` with a name that has no corresponding parameter, the function returns the string "postgresql::globals::<parameter-name>" which is probably not intended given the comment above the code. The usage of pick seems to indicate that an exception should be raised when a parameter is not found in `params` nor `globals.pp`, so adjust the code accordingly.
1 parent ba8e6d3 commit 6cb50cb

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

functions/default.pp

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ function postgresql::default(
1010

1111
#search for the variable name in params first
1212
#then fall back to globals if not found
13-
pick( getvar("postgresql::params::${parameter_name}"),
14-
"postgresql::globals::${parameter_name}")
13+
pick(getvar("postgresql::params::${parameter_name}"), getvar("postgresql::globals::${parameter_name}"))
1514
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'postgresql::default' do
6+
let(:facts) do
7+
{
8+
'os' => {
9+
'family' => 'Debian',
10+
'name' => 'Debian',
11+
'release' => {
12+
'full' => '11.7',
13+
'major' => '11',
14+
'minor' => '7',
15+
}
16+
}
17+
}
18+
end
19+
20+
let(:pre_condition) do
21+
<<~PP
22+
class { 'postgresql::server':
23+
}
24+
PP
25+
end
26+
27+
# parameter in params.pp only
28+
it { is_expected.to run.with_params('port').and_return(5432) }
29+
30+
# parameter in globals.pp only
31+
it { is_expected.to run.with_params('default_connect_settings').and_return({}) }
32+
33+
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}) }
34+
end

0 commit comments

Comments
 (0)