Revision history [back]

This is a bit of a necro, but it highlights an interesting case.

What are you trying to accomplish?

If you want to evaluate different values for different nodes... You can move your linux01.yaml etc under hieradata/nodes/ and add nodes/%{::certname} to your hiera.yaml Then in your test you can set the 'node' you are on with let(:node){ 'linux01' }, let hiera 'pick' the node specific data from the hierarchy for the test.

Otherwise, you may be able to mock out different hiera configs and data using something like https://github.com/bobtfish/hiera-puppet-helper .. I haven't used it, and I don't know if it is still maintained, or if there is a better gem available.

If you are trying to accomplish running different tests with different sets of hiera data, you can have a separate hiera.yaml (and/or separate hieradata directory referenced), and set the hieraconfig in the context for each of your tests.. I'm not sure how useful this scenario is for your directly but...

(also, common should be below any other values)

hiera01.yaml

---
:backends:
- yaml
:yaml:
:hierarchy:
- linux01
- common


hiera02.yaml

---
:backends:
- yaml
:yaml:
:hierarchy:
- linux02
- common


hiera03.yaml

---
:backends:
- yaml
:yaml:
:hierarchy:
- linux03
- common


and in your tests you could do

describe 'using the hiera01.yaml' do
let(:hiera_config) { 'spec/fixtures/hiera01.yaml' }
it do
should contain_exec('Create something lx01')
end
end
describe 'using the hiera02.yaml' do
let(:hiera_config) { 'spec/fixtures/hiera02.yaml' }
it do
should contain_exec('Create something lx02')
end
end
describe 'using the hiera03.yaml' do
let(:hiera_config) { 'spec/fixtures/hiera03.yaml' }
it do
should contain_exec('Create something lx03')
end
end


This is a bit of a necro, but it highlights an interesting case.

What are you trying to accomplish?

If you want to evaluate different values for different nodes... You can move your linux01.yaml etc under hieradata/nodes/ and add nodes/%{::certname} to your hiera.yaml Then in your test you can set the 'node' you are on with let(:node){ let(:node){ 'linux01' }, }, let hiera 'pick' the node specific data from the hierarchy for the test.

Otherwise, you may be able to mock out different hiera configs and data using something like https://github.com/bobtfish/hiera-puppet-helper .. I haven't used it, and I don't know if it is still maintained, or if there is a better gem available.

If you are trying to accomplish running different tests with different sets of hiera data, you can have a separate hiera.yaml (and/or separate hieradata directory referenced), and set the hieraconfig in the context for each of your tests.. I'm not sure how useful this scenario is for your directly but...

(also, common should be below any other values)

hiera01.yaml

---
:backends:
- yaml
:yaml:
:hierarchy:
- linux01
- common


hiera02.yaml

---
:backends:
- yaml
:yaml:
:hierarchy:
- linux02
- common


hiera03.yaml

---
:backends:
- yaml
:yaml:
:hierarchy:
- linux03
- common


and in your tests you could do

describe 'using the hiera01.yaml' do
let(:hiera_config) { 'spec/fixtures/hiera01.yaml' }
it do
should contain_exec('Create something lx01')
end
end
describe 'using the hiera02.yaml' do
let(:hiera_config) { 'spec/fixtures/hiera02.yaml' }
it do
should contain_exec('Create something lx02')
end
end
describe 'using the hiera03.yaml' do
let(:hiera_config) { 'spec/fixtures/hiera03.yaml' }
it do
should contain_exec('Create something lx03')
end
end