Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
DnZmfr opened this issue Feb 25, 2021 · 2 comments

Comments

@DnZmfr
Copy link

DnZmfr commented Feb 25, 2021

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 6.21.1
  • Ruby: 2.7.0
  • Distribution: Ubuntu 20.04.1 LTS
  • Module version: 8.1.0
  • Pdk: 2.0.0

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 DnZmfr closed this as completed Feb 25, 2021
@DnZmfr
Copy link
Author

DnZmfr commented Feb 25, 2021

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

@kenyon
Copy link
Member

kenyon commented Mar 1, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants