Search code examples
puppetrspec-puppet

rspec-puppet: cannot find class that is required


So I have a fully functional 'ldap' class.

Now I want to do some stuff for certain users in my ldap directory.

I do this in a new 'users' module, by first making a new defined_type:

define users::admin (
  String $sshkey
) {

  file {"/home/${title}":
    ensure => directory,
    owner => $title,
    group => 'root',
    require => Class['ldap']
  }
  ...
}

Then I use this defined type in my 'users' module's init.pp:

class users {
  users::admin {'ldt':
    sshkey => 'mysshkey',
  }
}

But when I try to use 'pdk test unit' on this, I get the following error:

failed: rspec: ./spec/classes/users_spec.rb:8: error during compilation:
Could not find resource 'Class[Ldap]' in parameter 'require'
(file: ~/Projects/puppet/modules/users/spec/fixtures/modules/users
/manifests/admin.pp, line: 15) on node <mycomputer>

For completeness's sake, here's my admin_spec.rb (barely changed from the pdk default):

require 'spec_helper'

describe 'users::admin' do
  let(:title) { 'namevar' }
  let(:params) do
    {
      'sshkey' => ''
    }
  end

  on_supported_os.each do |os, os_facts|
    context "on #{os}" do
      let(:facts) { os_facts }

      it { is_expected.to compile }
    end
  end
end

I tried setting my .fixtures.yml as follows, but that didn't help:

fixtures:
  symlinks:
    ldap: "#{source_dir}"

Any idea on what I'm doing wrong?

EDIT: changed my .fictures.yml to:

fixtures:
  symlinks:
    ldap: "#{source_dir}/../ldap"

Heck I even manually added a symlink to my ldap module in the spec/fixtures/modules folders. Still the same error.


Solution

  • So it turns out the error had nothing to do with rspec or anything.

    I just needed to 'include ldap' in my actual puppet code.