Skip to content

defined types facts as default parameter not working #13

@b4ldr

Description

@b4ldr

Describe the Bug

With a defined that has a default parameter which uses a fact for the default value e.g.

define example::rspec_define (
  $fact_parameter = $facts['os']['distro']['codename']
) {
  file{'/tmp/T291374':
    ensure  => file,
    content => $fact_parameter
  }
}

Testing using rspec-puppet-tests has no affect on the default value. It appears that all tests use the last value in the on_supported_os iterator.

The test i used is:

describe 'example::rspec_define' do
  on_supported_os(test_on).each do |os, facts|
    let(:facts) { facts }
    let(:title) { "test-#{os}" }
    context os do
      context 'test' do
        it { is_expected.to compile }
        it { is_expected.to contain_file('/tmp/T291374').with_content(/#{facts[:os]['distro']['codename']}/) }
      end
    end
  end
end

Expected Behaviour

All test should pass

Actual Behaviour

The file content test above fails when testing debian-10-x86_64 with the following error

  1) example::rspec_define debian-10-x86_64 test is expected to contain File[/tmp/T291374] with content =~ /buster/
     Failure/Error: it { is_expected.to contain_file('/tmp/T291374').with_content(/#{facts[:os]['distro']['codename']}/) }
       expected that the catalogue would contain File[/tmp/T291374] with content set to /buster/ but it is set to "stretch"
     # ./spec/defines/rspec_define_spec.rb:10:in `block (5 levels) in <top (required)>'

Steps to Reproduce

I have created a specific repo to demonstrate this issue
Steps to reproduce the behavior:

  1. git clone https://github.com/b4ldr/T291374/
  2. cd T291374
  3. bundle install
  4. bundle exec rake spec

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions