From 919ef976ccc577c6b77983f31d9adb235e4d026b Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Thu, 19 Oct 2023 14:01:56 +0200 Subject: [PATCH] (#1532) Replace ParserError with Puppet::Error I'm not sure how we ended up with ParserError in the provider. This exception doesn't exist in Ruby. Puppet ships ther own exception, Puppet::Error. It probably makes sense to raise that instead. --- lib/puppet/provider/postgresql_conf/ruby.rb | 2 +- spec/unit/provider/postgresql_conf/ruby_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/puppet/provider/postgresql_conf/ruby.rb b/lib/puppet/provider/postgresql_conf/ruby.rb index 63b87478d1..bc4c28b5bc 100644 --- a/lib/puppet/provider/postgresql_conf/ruby.rb +++ b/lib/puppet/provider/postgresql_conf/ruby.rb @@ -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 diff --git a/spec/unit/provider/postgresql_conf/ruby_spec.rb b/spec/unit/provider/postgresql_conf/ruby_spec.rb index 11800b0fc7..33f295391b 100644 --- a/spec/unit/provider/postgresql_conf/ruby_spec.rb +++ b/spec/unit/provider/postgresql_conf/ruby_spec.rb @@ -30,6 +30,13 @@ expect(provider).to respond_to(:exists?) end + describe 'duplicate keys in postgresql.conf' do + it 'raises an exception' do + allow(provider).to receive(:parse_config).and_return([{key: 'foo', line: 1}, {key: 'foo', line: 2}]) + 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