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