rodjek / rspec-puppet

RSpec tests for your Puppet manifests
http://rspec-puppet.com
MIT License
364 stars 203 forks source link

Mocking puppet master $settings::storeconfigs variable #801

Open b4ldr opened 4 years ago

b4ldr commented 4 years ago

I have a module which uses the $settings::storeconfig variable to ensure resources are only exported on systems which have sotreconfigs configured and im having trouble mocking the config setting. To test this out i have created a test module with the following puppet code.

class rspec_test {
    if $settings::storeconfigs {
        @@nagios_host {'confined':
            ensure => present
        }
    }
    @@nagios_host {'unconfined':
        ensure => present
    }
}

with the following test , the check for the confined resources fails as the clause for $settings::storeconfigs fails

describe 'rspec_test' do
  context 'test' do
    it { is_expected.to compile.with_all_deps }
  end
  context 'should have exported resources' do
    subject { exported_resources }
    it { is_expected.to contain_nagios_host('confined') }
    it { is_expected.to contain_nagios_host('unconfined') }
  end
end

I tried to update my tests by explicitly setting Puppet[:storeconfigs] = true. However this results in the error

ArgumentError:
       Could not find terminus puppetdb for indirection catalog

Is it possible to configure rspec to honour the settings::storeconfig variable without having to configure puppetdb.

full rspec output from both spec files avalible here

Thanks