Uploaded image for project: 'Puppet Development Kit'
  1. Puppet Development Kit
  2. PDK-1191

Cannot run unit tests if spec/default_facts.yml is empty

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: PDK 1.8.0
    • Component/s: None
    • Environment:
    • Template:
    • Method Found:
      Needs Assessment
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      Hide
      PDK now gracefully handles empty and invalid {{spec/default_facts.yml}} and {{spec/default_facts_module.yml}} files when running {{pdk test unit}}. If the file exists and is empty, it will be silently skipped. If the file is not empty and does not contain valid YAML data, a warning will be shown in the {{pdk test unit}} output.
      Show
      PDK now gracefully handles empty and invalid {{spec/default_facts.yml}} and {{spec/default_facts_module.yml}} files when running {{pdk test unit}}. If the file exists and is empty, it will be silently skipped. If the file is not empty and does not contain valid YAML data, a warning will be shown in the {{pdk test unit}} output.
    • QA Risk Assessment:
      Needs Assessment

      Description

      *Overview*
      Users may empty spec/default_facts.yml or create their own templates to empty it. If the file is empty spec_helper causes an error and fails all tests.

      Steps to reproduce
      1. Create new module
      2. Delete spec/default_facts.yml
      3. pdk new class
      4. pdk test unit

      Expected
      No test error due to missing facts

      *Actual*
      Tests fail due to missing facts file content

      geoff@computer:~/tmp$ pdk new module fcts --skip-interview
      pdk (INFO): Creating new module: fcts
      pdk (INFO): Module 'fcts' generated at path '/home/geoff/tmp/fcts', from template 'file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git'.
      pdk (INFO): In your module directory, add classes with the 'pdk new class' command.
      geoff@computer:~/tmp$ cd fcts
      geoff@computer:~/tmp/fcts$ echo > spec/default_facts.yml 
      geoff@computer:~/tmp/fcts$ pdk test unit
      pdk (INFO): Using Ruby 2.4.4
      pdk (INFO): Using Puppet 5.5.6
      [✔] Preparing to run the unit tests.
      [✔] Running unit tests.
      No examples found.
        Evaluated 0 tests in 0.00020046 seconds: 0 failures, 0 pending.
      geoff@computer:~/tmp/fcts$ pdk new class a
      pdk (INFO): Creating '/home/geoff/tmp/fcts/manifests/a.pp' from template.
      pdk (INFO): Creating '/home/geoff/tmp/fcts/spec/classes/a_spec.rb' from template.
      geoff@computer:~/tmp/fcts$ pdk test unit
      pdk (INFO): Using Ruby 2.4.4
      pdk (INFO): Using Puppet 5.5.6
      [✔] Preparing to run the unit tests.
      [✖] Running unit tests.
       
      An error occurred while loading ./spec/classes/a_spec.rb.
      Failure/Error: default_facts.merge!(YAML.safe_load(File.read(default_facts_path)))
       
      TypeError:
        no implicit conversion of nil into Hash
      # ./spec/spec_helper.rb:21:in `merge!'
      # ./spec/spec_helper.rb:21:in `<top (required)>'
      # ./spec/classes/a_spec.rb:1:in `require'
      # ./spec/classes/a_spec.rb:1:in `<top (required)>'
      No examples found.
        Evaluated 0 tests in 0.000219313 seconds: 0 failures, 0 pending.
      

      Workaround
      Add valid yaml content to spec/default_facts.yml and re-run tests

        Attachments

          Activity

            jsd-sla-details-panel

              People

              • Assignee:
                tim.sharpe Tim Sharpe
                Reporter:
                geoff@declarativesystems.com Geoff Williams
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: