puppetlabs / rspec-puppet

RSpec tests for your Puppet manifests
https://puppetlabs.github.io/rspec-puppet/
MIT License
13 stars 18 forks source link

Cannot use `file($settings::localcacert)` in my manifest, tests fail #59

Open threepistons opened 1 year ago

threepistons commented 1 year ago

Describe the Bug

When I try to write tests for a manifest to replace the CA cert across my nodes, very like this one. I get

1) profiles::replace_ca_cert All tests is expected to compile into a catalogue without dependency cycles
     Failure/Error: it { is_expected.to compile.with_all_deps }
       error during compilation: Evaluation Error: Error while evaluating a Function Call, Could not find any files from /dev/null/ssl/certs/ca.pem (file: /home/ucs/102/redacted/git/computing_linux_puppet_controlrepo/site/profiles/spec/fixtures/modules/profiles/manifests/replace_ca_cert.pp, line: 16, column: 16) on node redacted.uni.ac.uk
  7) profiles::replace_ca_cert All tests is expected to contain File[/etc/puppetlabs/puppet/ssl/certs/ca.pem] with ensure => "file" and replace => "yes"
     Failure/Error:
       is_expected.to contain_file('/etc/puppetlabs/puppet/ssl/certs/ca.pem').with(
         'ensure'  => 'file',
         'replace' => 'yes',
       )

     Puppet::PreformattedError:
       Evaluation Error: Error while evaluating a Function Call, Could not find any files from /dev/null/ssl/certs/ca.pem (file: /home/ucs/102/redacted/git/computing_linux_puppet_controlrepo/site/profiles/spec/fixtures/modules/profiles/manifests/replace_ca_cert.pp, line: 16, column: 16) on node redacted.uni.ac.uk

and further identical errors for each OS under test.

Expected Behaviour

I expected the manifest to compile.

Steps to Reproduce

Steps to reproduce the behaviour:

  1. pdk new class replace_ca_cert in my profiles module.
  2. Paste replace_ca_cert.pp.txt into manifests/replace_ca_cert.pp.
  3. Paste replace_ca_cert_spec.rb.txt into spec/classes/replace_ca_cert_spec.rb.
  4. pdk validate ; pdk test unit

Environment

Additional Context

Replacing the file resource's content with a string instead of file($settings::localcacert) in replace_ca_cert.pp compiled perfectly, but that's not the behaviour I need.

I'm hoping that the answer turns out to be something really simple like "put X line into Y file". Google, Stack Exchange, etc revealed nothing of the sort.

threepistons commented 1 year ago

I get the same result with PDK 3.0.0 on a different system.

mmarseglia commented 1 month ago

Hi @threepistons did you ever find a solution? I have the same issue.