Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-3138

improve spec functions "produces" and "fails" in language.rb

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Ready for Engineering
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: PUP 5.y
    • Component/s: None
    • Labels:
      None
    • Template:
    • Story Points:
      1

      Description

      The spec functions "produces" and "fails" makes it easy to write spec tests by giving it a hash of puppet source to expected results (a value or an error respectively for the two functions).

      The wanted improvement is when the expectancy is not met. Since the function runs its own spec test, the error is reported as originating from language.rb and there is no trace of which test called it except for the source string being tested.

      Earlier when the loop was performed in the file doing the source to expectancy mapping there was at least a reference to the file / line in the loop.

      The current way the failure appears when reported makes it hard to figure out where the problem is.

      The output may look like this:

       1) Puppet resource expressions future parser parameters fails to evaluate notify { title: message => oops, * => { hash => value } } with message (?-mix:Invalid parameter hush)
           Failure/Error: expect do
             expected Puppet::Error with message matching /Invalid parameter hush/, got #<Puppet::Error: Invalid parameter hash on Notify[title] at line 1 on node foonode> with backtrace:
               # ./lib/puppet/resource.rb:506:in `validate_parameter'
               # ./lib/puppet/parser/resource.rb:263:in `block in validate'
               # ./lib/puppet/parser/resource.rb:262:in `each'
               # ./lib/puppet/parser/resource.rb:262:in `validate'
               # ./lib/puppet/parser/resource.rb:107:in `finish'
               # ./lib/puppet/parser/compiler.rb:460:in `block in finish'
               # ./lib/puppet/parser/compiler.rb:448:in `each'
               # ./lib/puppet/parser/compiler.rb:448:in `finish'
               # ./lib/puppet/parser/compiler.rb:128:in `block (2 levels) in compile'
               # ./lib/puppet/util/profiler/around_profiler.rb:58:in `profile'
               # ./lib/puppet/util/profiler.rb:51:in `profile'
               # ./lib/puppet/parser/compiler.rb:128:in `block in compile'
               # ./lib/puppet/context.rb:64:in `override'
               # ./lib/puppet.rb:244:in `override'
               # ./lib/puppet/parser/compiler.rb:106:in `compile'
               # ./lib/puppet/parser/compiler.rb:23:in `compile'
               # ./spec/lib/puppet_spec/compiler.rb:7:in `compile_to_catalog'
               # ./spec/lib/puppet_spec/language.rb:52:in `block (3 levels) in fails'
               # ./spec/lib/puppet_spec/language.rb:51:in `block (2 levels) in fails'
           # ./spec/lib/puppet_spec/language.rb:51:in `block (2 levels) in fails'
      
      

      Which comes from this:

            fails(
              "notify { title: unknown => value }" => /Invalid parameter unknown/,
       
              #BUG
              "notify { title: * => { hash => value }, message => oops }" => /Invalid parameter hash/, # this really needs to be a better error message.
              "notify { title: message => oops, * => { hash => value } }" => /Invalid parameter hash/, # should this be a better error message?
       
              "notify { title: * => { unknown => value } }" => /Invalid parameter unknown/)
      

      in file integration/parser/resource_expressions_spec.rb (line 142-149) (Now with the problem on line 147 corrected - it generated a SyntaxError earlier, but it now correctly issues an "Invalid parameter hash".

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            henrik.lindberg Henrik Lindberg
            QA Contact:
            Kurt Wall
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:

                Zendesk Support