Skip to content

Commit e1c3a24

Browse files
authored
Merge pull request #1530 from puppetlabs/fix-postgresql_default
Fix `postgresql::default()` return value for unknown parameters
2 parents f2f2754 + 4e15857 commit e1c3a24

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

Diff for: functions/default.pp

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ function postgresql::default(
88
) {
99
include postgresql::params
1010

11-
#search for the variable name in params first
12-
#then fall back to globals if not found
13-
pick( getvar("postgresql::params::${parameter_name}"),
14-
"postgresql::globals::${parameter_name}")
11+
# Search for the variable name in params.
12+
# params inherits from globals, so it will also catch these variables.
13+
pick(getvar("postgresql::params::${parameter_name}"))
1514
}

Diff for: spec/functions/postgresql_default_spec.rb

+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)