puppetlabs / pdk

The shortest path to better modules: Puppet Development Kit; Download:
https://puppet.com/download-puppet-development-kit
Apache License 2.0
223 stars 104 forks source link

Validate and Test failing on new module #811

Closed PaulWalkerUK closed 4 years ago

PaulWalkerUK commented 4 years ago

Describe the bug Using PDK 1.14.1 on Windows (installed via Chocolatey), I get a lot of validation errors on the files that are created by new module. Also after creating a new class, test unit doesn't execute the default tests, but test unit --list --verbose does see them.

To Reproduce

  1. Create a new module with pdk new module pwtest and just accept the default at all prompts

  2. Go into the new directory

  3. Run pdk validate. It gives messages such as:

    ~\git\pwtest> pdk validate
    pdk (INFO): Running all available validators...
    pdk (INFO): Using Ruby 2.5.7
    pdk (INFO): Using Puppet 6.10.1
    [*] Checking metadata syntax (metadata.json tasks/*.json).
    [*] Checking module metadata style (metadata.json).
    [*] Checking YAML syntax (["**/*.yaml", "*.yaml", "**/*.yml", "*.yml"]).
    [X] Checking Ruby code style (**/**.rb).
    [*] Checking task names (tasks/**/*).
    info: puppet-syntax: ./: Target does not contain any files to validate (**/*.pp).
    info: puppet-lint: ./: Target does not contain any files to validate (**/*.pp).
    info: puppet-epp: ./: Target does not contain any files to validate (**/*.epp).
    convention: rubocop: Gemfile:1:1: Style/FileName: The name of this source file (`Gemfile`) should use snake_case.
    convention: rubocop: Gemfile:20:7: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
    convention: rubocop: Gemfile:21:3: Bundler/DuplicatedGem: Gem `fast_gettext` requirements already given on line 20 of the Gemfile.
    convention: rubocop: Gemfile:21:7: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
    convention: rubocop: Gemfile:22:7: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
    ...
    convention: rubocop: Rakefile:1:1: Style/FileName: The name of this source file (`Rakefile`) should use snake_case.
    convention: rubocop: Rakefile:9:59: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
    convention: rubocop: Rakefile:10:3: Style/VariableName: Use snake_case for variable names.
    convention: rubocop: Rakefile:10:27: Security/JSONLoad: Prefer `JSON.parse` over `JSON.load`.
    ...
    convention: rubocop: bin/metadata-json-lint:11:9: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
    convention: rubocop: bin/metadata-json-lint:12:5: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
    convention: rubocop: bin/metadata-json-lint:12:44: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
    convention: rubocop: bin/metadata-json-lint:13:3: Layout/AlignParameters: Align the parameters of a method call if they span more than one line.
    ...
    convention: rubocop: bin/rubocop:11:9: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
    convention: rubocop: bin/rubocop:12:5: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
    convention: rubocop: bin/rubocop:12:44: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
    convention: rubocop: bin/rubocop:13:3: Layout/AlignParameters: Align the parameters of a method call if they span more than one line.
    ...
    convention: rubocop: bin/rubocop:27:9: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
    convention: rubocop: bin/rubocop:29:19: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
    convention: rubocop: bin/rubocop:29:30: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
    info: task-metadata-lint: ./: Target does not contain any files to validate (tasks/*.json).
  4. Create a new class with pdk new class pwclass

  5. Running pdk test unit doesn't execute any tests:

~\git\pwtest> pdk test unit
pdk (INFO): Using Ruby 2.5.7
pdk (INFO): Using Puppet 6.10.1
[*] Preparing to run the unit tests.
"C:/Program Files/Puppet Labs/DevelopmentKit/private/ruby/2.5.7/bin/ruby.exe" -I'C:/Program Files/Puppet Labs/DevelopmentKit/share/cache/ruby/2.5.0/gems/rspec-core-3.9.0/lib';'C:/Program Files/Puppet Labs/DevelopmentKit/share/cache/ruby/2.5.0/gems/rspec-support-3.9.0/lib' 'C:/Program Files/Puppet Labs/DevelopmentKit/share/cache/ruby/2.5.0/gems/rspec-core-3.9.0/exe/rspec' --pattern 'spec/{aliases,classes,defines,functions,hosts,integration,plans,tasks,type_aliases,types,unit}/**/*_spec.rb' --format progress
Run options: exclude {:bolt=>true}
Cannot create a file when that file already exists.

Deprecation Warnings:

puppetlabs_spec_helper: defaults `mock_with` to `:mocha`. See https://github.com/puppetlabs/puppetlabs_spec_helper#mock_with to choose a sensible value for you

If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

1 deprecation warning total

Finished in 0.04638 seconds (files took 57.6 seconds to load)
0 examples, 0 failures

"C:/Program Files/Puppet Labs/DevelopmentKit/private/ruby/2.5.7/bin/ruby.exe" -I'C:/Program Files/Puppet Labs/DevelopmentKit/share/cache/ruby/2.5.0/gems/rspec-core-3.9.0/lib';'C:/Program Files/Puppet Labs/DevelopmentKit/share/cache/ruby/2.5.0/gems/rspec-support-3.9.0/lib' 'C:/Program Files/Puppet Labs/DevelopmentKit/share/cache/ruby/2.5.0/gems/rspec-core-3.9.0/exe/rspec' --pattern 'spec/{aliases,classes,defines,functions,hosts,integration,plans,tasks,type_aliases,types,unit}/**/*_spec.rb' --format progress failed
  1. But running pdk test unit --list --verbose does show them:
    ~\git\pwtest> pdk test unit --list --verbose
    pdk (INFO): Using Ruby 2.5.7
    pdk (INFO): Using Puppet 6.10.1
    [*] Finding unit tests.
    Unit Test Files:
    ./spec/classes/pwclass_spec.rb
        ./spec/classes/pwclass_spec.rb[1:1:1]   pwtest::pwclass on centos-7-x86_64
        ./spec/classes/pwclass_spec.rb[1:2:1]   pwtest::pwclass on debian-9-x86_64
        ./spec/classes/pwclass_spec.rb[1:3:1]   pwtest::pwclass on oraclelinux-7-x86_64
        ./spec/classes/pwclass_spec.rb[1:4:1]   pwtest::pwclass on redhat-8-x86_64
        ./spec/classes/pwclass_spec.rb[1:5:1]   pwtest::pwclass on scientific-7-x86_64
        ./spec/classes/pwclass_spec.rb[1:6:1]   pwtest::pwclass on ubuntu-18.04-x86_64
        ./spec/classes/pwclass_spec.rb[1:7:1]   pwtest::pwclass on windows-10-x64
    C:/Users/Paul/Git/pwtest/spec/classes/pwclass_spec.rb
        C:/Users/Paul/Git/pwtest/spec/classes/pwclass_spec.rb[1:1:1]    pwtest::pwclass on centos-7-x86_64
        C:/Users/Paul/Git/pwtest/spec/classes/pwclass_spec.rb[1:2:1]    pwtest::pwclass on debian-9-x86_64
        C:/Users/Paul/Git/pwtest/spec/classes/pwclass_spec.rb[1:3:1]    pwtest::pwclass on oraclelinux-7-x86_64
        C:/Users/Paul/Git/pwtest/spec/classes/pwclass_spec.rb[1:4:1]    pwtest::pwclass on redhat-8-x86_64
        C:/Users/Paul/Git/pwtest/spec/classes/pwclass_spec.rb[1:5:1]    pwtest::pwclass on scientific-7-x86_64
        C:/Users/Paul/Git/pwtest/spec/classes/pwclass_spec.rb[1:6:1]    pwtest::pwclass on ubuntu-18.04-x86_64
        C:/Users/Paul/Git/pwtest/spec/classes/pwclass_spec.rb[1:7:1]    pwtest::pwclass on windows-10-x64

    Expected behavior After creating a new module and a new class, pdk validate should return no issues and pdk test unit should execute (and pass) the default tests.

Additional context

At first, this seemed intermittent, but now it seems to happen all the time. I'm fairly new to Puppet etc, but I'm not aware of having done anything to contribute to this! 😄

rodjek commented 4 years ago

@PaulWalkerUK are you using a custom template to generate your module? Would you mind zipping up your pwtest module and attacting it to the issue?

PaulWalkerUK commented 4 years ago

I think we may have found my issue...! When I tried zipping it up (just through the standard Windows GUI "Send to compressed folder"), I got a message saying The compression cannot be poerformed because the path to the file or directory 'pwtest' is too long. I copied this folder to C:\git and pdk validate and pdk test unit work as expected (the original path was C:\Users\Paul\Git\pwtest. Guess there must be some quite long path names!

PaulWalkerUK commented 4 years ago

I think we may have found my issue...! When I tried zipping it up (just through the standard Windows GUI "Send to compressed folder"), I got a message saying The compression cannot be performed because the path to the file or directory 'pwtest' is too long. 7-Zip also failed with Incorrect function. I copied the folder to C:\git and now both pdk validate and pdk test unit work as expected (the original path was C:\Users\Paul\Git\pwtest). Guess there must be some quite long path names!

No, I'm not using a custom template. I've zipped and attached the module, after moving it to C:\git (Windows standard functionality still struggled to zip it - I think maybe because of the recursion in spec\fixtures\modules (?) but 7-zip was able to deal with it).

So it looks like everything's OK when the base folder is c:\git instead of C:\Users\Paul\Git

pwtest.zip

PaulWalkerUK commented 4 years ago

Just in case anyone else stumbles across this in the future...

Even after moving the module to C:\git\, I was still having an issue with pdk test unit not executing any tests and comng back with Cannot create a file when that file already exists. I fixed it by deleting C:\git\puppet-xorg\spec\fixtures\modules. Next time I ran pdk test unit it was successful, an recreated that modules directory.