Skip to content

Commit

Permalink
(#1532) Replace ParserError with Puppet::Error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bastelfreak committed Oct 19, 2023
1 parent d4560c1 commit 919ef97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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
7 changes: 7 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,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}])

Check failure on line 35 in spec/unit/provider/postgresql_conf/ruby_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

Layout/SpaceInsideHashLiteralBraces: Space inside { missing. (https://rubystyle.guide#spaces-braces)

Check failure on line 35 in spec/unit/provider/postgresql_conf/ruby_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

Layout/SpaceInsideHashLiteralBraces: Space inside } missing. (https://rubystyle.guide#spaces-braces)

Check failure on line 35 in spec/unit/provider/postgresql_conf/ruby_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

Layout/SpaceInsideHashLiteralBraces: Space inside { missing. (https://rubystyle.guide#spaces-braces)

Check failure on line 35 in spec/unit/provider/postgresql_conf/ruby_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

Layout/SpaceInsideHashLiteralBraces: Space inside } missing. (https://rubystyle.guide#spaces-braces)

Check failure on line 35 in spec/unit/provider/postgresql_conf/ruby_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Layout/SpaceInsideHashLiteralBraces: Space inside { missing. (https://rubystyle.guide#spaces-braces)

Check failure on line 35 in spec/unit/provider/postgresql_conf/ruby_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Layout/SpaceInsideHashLiteralBraces: Space inside } missing. (https://rubystyle.guide#spaces-braces)

Check failure on line 35 in spec/unit/provider/postgresql_conf/ruby_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Layout/SpaceInsideHashLiteralBraces: Space inside { missing. (https://rubystyle.guide#spaces-braces)

Check failure on line 35 in spec/unit/provider/postgresql_conf/ruby_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Layout/SpaceInsideHashLiteralBraces: Space inside } missing. (https://rubystyle.guide#spaces-braces)
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

0 comments on commit 919ef97

Please sign in to comment.