[PDK-1191] Cannot run unit tests if spec/default_facts.yml is empty Created: 2018/09/26  Updated: 2018/11/29  Resolved: 2018/10/29

Status: Closed
Project: Puppet Development Kit
Component/s: None
Affects Version/s: None
Fix Version/s: PDK 1.8.0

Type: Bug Priority: Normal
Reporter: Geoff Williams Assignee: Tim Sharpe
Resolution: Fixed Votes: 0
Labels: resolved-issue-added
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

geoff@computer:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.1 LTS
Release:	18.04
Codename:	bionic
geoff@computer:~$ pdk --version
1.7.0


Template:
Method Found: Needs Assessment
Release Notes: Bug Fix
Release Notes Summary: 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


Generated at Sun Jul 21 01:28:04 PDT 2019 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.