Skip to content

(#1532) Replace ParserError with Puppet::Error #1538

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion lib/puppet/provider/postgresql_conf/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def write_config(file, lines)
# check, if resource exists in postgresql.conf file
def exists?
select = parse_config.select { |hash| hash[:key] == resource[:key] }
raise ParserError, "found multiple config items of #{resource[:key]} found, please fix this" if select.length > 1
raise Puppet::Error, "found multiple config items of #{resource[:key]} found, please fix this" if select.length > 1
return false if select.empty?

@result = select.first
Expand Down
10 changes: 10 additions & 0 deletions spec/unit/provider/postgresql_conf/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
expect(provider).to respond_to(:exists?)
end

describe 'duplicate keys in postgresql.conf' do
it 'stubs the parse_config method' do
allow(provider).to receive(:parse_config).and_return([{ key: 'foo', line: 1 }, { key: 'foo', line: 2 }])
expect(provider).to have_received(:parse_config)
end
it 'raises an exception' do
expect { provider.exists? }.to raise_error(Puppet::Error, 'found multiple config items of foo found, please fix this')
end
end

it 'has a method create' do
expect(provider).to respond_to(:create)
end
Expand Down