Skip to content

Fix postgresql::default() return value for unknown parameters #1530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 12, 2023
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: 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}"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Late to the party, but what's the point of using pick() with a single parameter? Isn't just getvar() the same?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getvar('nothing_here') returns undef. Since pick was already there, I assumed we wanted to have a strong failure with an exception in that case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspected that, but good to hear that explicitly.

}
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