Skip to content

mysql_grant: Output missmatching data during validation #1666

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bastelfreak
Copy link
Collaborator

@bastelfreak bastelfreak commented Mar 18, 2025

The type does some validation for the title and user/table. It's helpful to output the data when the validation doesn't succeed.

Summary

Provide a detailed description of all the changes present in this pull request.

Additional Context

Add any additional context about the problem here.

  • Root cause and the steps to reproduce. (If applicable)
  • Thought process behind the implementation.

Related Issues (if any)

Mention any related issues or pull requests.

Checklist

  • 🟢 Spec tests.
  • 🟢 Acceptance tests.
  • Manually verified. (For example puppet apply)

The type does some validation for the title and user/table. It's helpful
to output the data when the validation doesn't succeed.
@bastelfreak bastelfreak self-assigned this Mar 18, 2025
@bastelfreak bastelfreak requested review from alexjfisher and a team as code owners March 18, 2025 09:56
@@ -37,7 +37,9 @@ def initialize(*args)
raise(_('mysql_grant: `table` `parameter` is required.')) if self[:ensure] == :present && self[:table].nil?
raise(_('mysql_grant: `user` `parameter` is required.')) if self[:ensure] == :present && self[:user].nil?

raise(_('mysql_grant: `name` `parameter` must match user@host/table format.')) if self[:user] && self[:table] && (self[:name] != "#{self[:user]}/#{self[:table]}")
if self[:user] && self[:table] && (self[:name] != "#{self[:user]}/#{self[:table]}")

Choose a reason for hiding this comment

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

Following spec tests are failing, can you please check on this

Failures:

  1) Facter::Util::Fact mysql_server_id igalic's laptop 
     Failure/Error: Facter.fact(:macaddress).stubs(:value).returns('3c:97:0e:69:fb:e1')
     
     Mocha::StubbingError:
       can't stub method on frozen object: nil
     # ./spec/unit/facter/mysql_server_id_spec.rb:11:in `block (4 levels) in <top (required)>'

  2) Facter::Util::Fact mysql_server_id node with lo only 
     Failure/Error: Facter.fact(:macaddress).stubs(:value).returns('00:00:00:00:00:00')
     
     Mocha::StubbingError:
       can't stub method on frozen object: nil
     # ./spec/unit/facter/mysql_server_id_spec.rb:20:in `block (4 levels) in <top (required)>'

  3) function_mysql_deepmerge when calling mysql_deepmerge from puppet should not compile when no arguments are passed
     Failure/Error:
       expect {
         scope.compiler.compile
       }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
     
       expected Puppet::ParseError with message matching /wrong number of arguments/, got #<NoMethodError: undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
     
         let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                      ^^^^^^> with backtrace:
         # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:6:in `block (2 levels) in <top (required)>'
         # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:13:in `block (4 levels) in <top (required)>'
         # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:12:in `block (3 levels) in <top (required)>'
     # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:12:in `block (3 levels) in <top (required)>'

  4) function_mysql_deepmerge when calling mysql_deepmerge from puppet should not compile when 1 argument is passed
     Failure/Error:
       expect {
         scope.compiler.compile
       }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
     
       expected Puppet::ParseError with message matching /wrong number of arguments/, got #<NoMethodError: undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
     
         let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                      ^^^^^^> with backtrace:
         # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:6:in `block (2 levels) in <top (required)>'
         # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:21:in `block (4 levels) in <top (required)>'
         # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:20:in `block (3 levels) in <top (required)>'
     # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:20:in `block (3 levels) in <top (required)>'

  5) function_mysql_deepmerge when calling mysql_deepmerge on the scope instance should require all parameters are hashes
     Failure/Error: expect { new_hash = scope.function_mysql_deepmerge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/)
     
       expected Puppet::ParseError with message matching /unexpected argument type String/, got #<NoMethodError: undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
     
         let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                      ^^^^^^> with backtrace:
         # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:6:in `block (2 levels) in <top (required)>'
         # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:28:in `block (4 levels) in <top (required)>'
         # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:28:in `block (3 levels) in <top (required)>'
     # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:28:in `block (3 levels) in <top (required)>'

  6) function_mysql_deepmerge when calling mysql_deepmerge on the scope instance should accept empty strings as puppet undef
     Failure/Error: expect { new_hash = scope.function_mysql_deepmerge([{}, ''])}.not_to raise_error
     
       expected no Exception, got #<NoMethodError: undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
     
         let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                      ^^^^^^> with backtrace:
         # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:6:in `block (2 levels) in <top (required)>'
         # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:33:in `block (4 levels) in <top (required)>'
         # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:33:in `block (3 levels) in <top (required)>'
     # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:33:in `block (3 levels) in <top (required)>'

  7) function_mysql_deepmerge when calling mysql_deepmerge on the scope instance should be able to mysql_deepmerge two hashes
     Failure/Error: let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
     
     NoMethodError:
       undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
     
         let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                      ^^^^^^
     # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:6:in `block (2 levels) in <top (required)>'
     # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:37:in `block (3 levels) in <top (required)>'

  8) function_mysql_deepmerge when calling mysql_deepmerge on the scope instance should mysql_deepmerge multiple hashes
     Failure/Error: let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
     
     NoMethodError:
       undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
     
         let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                      ^^^^^^
     # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:6:in `block (2 levels) in <top (required)>'
     # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:44:in `block (3 levels) in <top (required)>'

  9) function_mysql_deepmerge when calling mysql_deepmerge on the scope instance should accept empty hashes
     Failure/Error: let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
     
     NoMethodError:
       undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
     
         let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                      ^^^^^^
     # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:6:in `block (2 levels) in <top (required)>'
     # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:49:in `block (3 levels) in <top (required)>'

  10) function_mysql_deepmerge when calling mysql_deepmerge on the scope instance should mysql_deepmerge subhashes
      Failure/Error: let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
      
      NoMethodError:
        undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
      
          let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                       ^^^^^^
      # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:6:in `block (2 levels) in <top (required)>'
      # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:53:in `block (3 levels) in <top (required)>'

  11) function_mysql_deepmerge when calling mysql_deepmerge on the scope instance should append to subhashes
      Failure/Error: let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
      
      NoMethodError:
        undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
      
          let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                       ^^^^^^
      # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:6:in `block (2 levels) in <top (required)>'
      # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:60:in `block (3 levels) in <top (required)>'

  12) function_mysql_deepmerge when calling mysql_deepmerge on the scope instance should append to subhashes 2
      Failure/Error: let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
      
      NoMethodError:
        undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
      
          let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                       ^^^^^^
      # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:6:in `block (2 levels) in <top (required)>'
      # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:65:in `block (3 levels) in <top (required)>'

  13) function_mysql_deepmerge when calling mysql_deepmerge on the scope instance should append to subhashes 3
      Failure/Error: let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
      
      NoMethodError:
        undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
      
          let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                       ^^^^^^
      # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:6:in `block (2 levels) in <top (required)>'
      # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:72:in `block (3 levels) in <top (required)>'

  14) function_mysql_deepmerge when calling mysql_deepmerge on the scope instance should equate keys mod dash and underscore
      Failure/Error: let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
      
      NoMethodError:
        undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
      
          let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                       ^^^^^^
      # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:6:in `block (2 levels) in <top (required)>'
      # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:78:in `block (3 levels) in <top (required)>'

  15) function_mysql_deepmerge when calling mysql_deepmerge on the scope instance should keep style of the last when keys are euqal mod dash and underscore
      Failure/Error: let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
      
      NoMethodError:
        undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
      
          let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                       ^^^^^^
      # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:6:in `block (2 levels) in <top (required)>'
      # ./spec/unit/puppet/functions/mysql_deepmerge_spec.rb:84:in `block (3 levels) in <top (required)>'

  16) the mysql_password function should raise a ParseError if there is less than 1 arguments
      Failure/Error: expect { scope.function_mysql_password([]) }.to( raise_error(Puppet::ParseError))
      
        expected Puppet::ParseError, got #<NoMethodError: undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
      
          let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                       ^^^^^^> with backtrace:
          # ./spec/unit/puppet/functions/mysql_password_spec.rb:8:in `block (2 levels) in <top (required)>'
          # ./spec/unit/puppet/functions/mysql_password_spec.rb:15:in `block (3 levels) in <top (required)>'
          # ./spec/unit/puppet/functions/mysql_password_spec.rb:15:in `block (2 levels) in <top (required)>'
      # ./spec/unit/puppet/functions/mysql_password_spec.rb:15:in `block (2 levels) in <top (required)>'

  17) the mysql_password function should raise a ParseError if there is more than 1 arguments
      Failure/Error: expect { scope.function_mysql_password(%w(foo bar)) }.to( raise_error(Puppet::ParseError))
      
        expected Puppet::ParseError, got #<NoMethodError: undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
      
          let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                       ^^^^^^> with backtrace:
          # ./spec/unit/puppet/functions/mysql_password_spec.rb:8:in `block (2 levels) in <top (required)>'
          # ./spec/unit/puppet/functions/mysql_password_spec.rb:19:in `block (3 levels) in <top (required)>'
          # ./spec/unit/puppet/functions/mysql_password_spec.rb:19:in `block (2 levels) in <top (required)>'
      # ./spec/unit/puppet/functions/mysql_password_spec.rb:19:in `block (2 levels) in <top (required)>'

  18) the mysql_password function should convert password into a hash
      Failure/Error: let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
      
      NoMethodError:
        undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
      
          let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                       ^^^^^^
      # ./spec/unit/puppet/functions/mysql_password_spec.rb:8:in `block (2 levels) in <top (required)>'
      # ./spec/unit/puppet/functions/mysql_password_spec.rb:23:in `block (2 levels) in <top (required)>'

  19) the mysql_password function should convert an empty password into a empty string
      Failure/Error: let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
      
      NoMethodError:
        undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
      
          let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                       ^^^^^^
      # ./spec/unit/puppet/functions/mysql_password_spec.rb:8:in `block (2 levels) in <top (required)>'
      # ./spec/unit/puppet/functions/mysql_password_spec.rb:28:in `block (2 levels) in <top (required)>'

  20) the mysql_password function should not convert a password that is already a hash
      Failure/Error: let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
      
      NoMethodError:
        undefined method `scope' for PuppetlabsSpec::PuppetInternals:Module
      
          let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
                                                       ^^^^^^
      # ./spec/unit/puppet/functions/mysql_password_spec.rb:8:in `block (2 levels) in <top (required)>'
      # ./spec/unit/puppet/functions/mysql_password_spec.rb:33:in `block (2 levels) in <top (required)>'

Finished in 0.85942 seconds (files took 1.04 seconds to load)
117 examples, 20 failures

@vikasPerforce
Copy link

Although not related to your change, can you please fix lint error so that spec test cases will run
manifests/backup/mysqlbackup.pp - WARNING: there should be a single space before '=>' on line 48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants