voxpupuli / puppet-nodejs

Puppet module to install nodejs and global npm packages
https://forge.puppet.com/puppet/nodejs
Apache License 2.0
113 stars 248 forks source link

Evaluation Error: Operator '[]' is not applicable to an Undef Value - Ubuntu 20.04 #440

Closed DnZmfr closed 3 years ago

DnZmfr commented 3 years ago

Affected Puppet, Ruby, OS and module versions/distributions

How to reproduce (e.g Puppet code you use)

pdk test unit --tests=./spec/classes/opencv_spec.rb

custom_module/manifests/linux/opencv.pp

class payback_mobile::linux::opencv {

  file { '/usr/lib/node_modules':
    ensure => 'directory',
    owner  => root,
    group  => root,
    mode   => '0777',
  }

  -> package { 'cmake':
    ensure => present,
  }

  -> package { 'opencv4nodejs':
    ensure   => present,
    provider => npm,
    require  => Class['nodejs'],
  }
}

custom_module/spec/classes/opencv_spec.rb

require 'spec_helper'

describe 'custom_module::linux::opencv' do
  let(:pre_condition) { 'include nodejs' }

  context 'Ubuntu 20.04' do
    let :facts do
      {
        lsbdistrelease: '20.04',
        osfamily: 'Debian',
        operatingsystem: 'Ubuntu',
        operatingsystemrelease: '20.04',
      }
    end

    it { is_expected.to compile }
    it { is_expected.to contain_file('/usr/lib/node_modules') }
    it { is_expected.to contain_package('cmake') }
    it { is_expected.to contain_package('opencv4nodejs') }
  end
end

What are you seeing

  1) custom_module::linux::opencv Ubuntu 20.04 is expected to compile into a catalogue without dependency cycles
     Failure/Error: it { is_expected.to compile }
       error during compilation: Evaluation Error: Operator '[]' is not applicable to an Undef Value. (file: /home/puppet/custom_module/spec/fixtures/modules/nodejs/manifests/params.pp, line: 17, column: 19) on node muc-pvl-mds-02.loyaltypartner.com
...
  2) custom_module::linux::opencv Ubuntu 20.04 is expected to contain File[/usr/lib/node_modules]
     Failure/Error: it { is_expected.to contain_file('/usr/lib/node_modules') }

     Puppet::PreformattedError:
       Evaluation Error: Operator '[]' is not applicable to an Undef Value. (file: /home/ci_de/custom_module/spec/fixtures/modules/nodejs/manifests/params.pp, line: 17, column: 19) on node muc-pvl-mds-02.loyaltypartner.com
...
  3) custom_module::linux::opencv Ubuntu 20.04 is expected to contain Package[cmake]
     Failure/Error: it { is_expected.to contain_package('cmake') }

     Puppet::PreformattedError:
       Evaluation Error: Operator '[]' is not applicable to an Undef Value. (file: /home/ci_de/custom_module/spec/fixtures/modules/nodejs/manifests/params.pp, line: 17, column: 19) on node muc-pvl-mds-02.loyaltypartner.com
...
  4) custom_module::linux::opencv Ubuntu 20.04 is expected to contain Package[opencv4nodejs]
     Failure/Error: it { is_expected.to contain_package('opencv4nodejs') }

     Puppet::PreformattedError:
       Evaluation Error: Operator '[]' is not applicable to an Undef Value. (file: /home/ci_de/custom_module/spec/fixtures/modules/nodejs/manifests/params.pp, line: 17, column: 19) on node muc-pvl-mds-02.loyaltypartner.com
...

Finished in 5.95 seconds (files took 1.79 seconds to load)
24 examples, 4 failures

Failed examples:

rspec ./spec/classes/opencv_spec.rb:16 # custom_module::linux::opencv Ubuntu 20.04 is expected to compile into a catalogue without dependency cycles
rspec ./spec/classes/opencv_spec.rb:17 # custom_module::linux::opencv Ubuntu 20.04 is expected to contain File[/usr/lib/node_modules]
rspec ./spec/classes/opencv_spec.rb:18 # custom_module::linux::opencv Ubuntu 20.04 is expected to contain Package[cmake]
rspec ./spec/classes/opencv_spec.rb:19 # custom_module::linux::opencv Ubuntu 20.04 is expected to contain Package[opencv4nodejs]

What behaviour did you expect instead

Finished in x.xx seconds...
24 examples, 0 failures

Output log

See above.

Any additional information you'd like to impart

DnZmfr commented 3 years ago

I decided to add the nodejs packages in hieradata with nodejs::npm

kenyon commented 3 years ago

This is a problem with the tests in your custom_module. If you use on_supported_os.each do |os, facts| et cetera, from https://github.com/mcanevet/rspec-puppet-facts like we do with @voxpupuli modules, you won't have this problem because you'll have all of the modern OS facts defined.