I am writting a custom puppet module which includes an ::apache::vhost resource, and would like to verify in my rspec tests that the directories parameter contains a certain value, without reproducing the entire directories configuration which is mostly hardcoded in the spec test.
class foo::apache {
# prepend 'from ' to each element in array of subnets
# Change this ugliness to use map once we've upgraded to puppet v4
# open to suggetions on better way to do this too...
$subnets = $::foo::subnets
$subnets_yaml = inline_template('<%= subnets.map {|s| "from " +s}.to_yaml %>')
$allowed_subnets_directives = parseyaml($subnets_yaml)
::apache::vhost { 'foo_vhost':
directories => [
-- snip --
##### How can I check just the path & allow keys of this element?
{ 'path' => '~^.*$',
'Order' => 'deny,allow',
'allow' => concat(['from localhost'],
$allowed_subnets_directives),
'provider' => 'location',
},
]
} # foo_vhost
} # foo::apache
I've removed most of the manifest for brevity.
I can test the entire directives parameter with something along the lines of
describe 'foo::apache' do
it { is_expected.to contain_apache__vhost('foo_vhost').with(
'directories' => [{'path' => '~^.*$',
'allow' => ['from localhost',
'from 10.20.30/24',
],},
]
but the directories parameter is long and static, and I'm keen to avoid that.
The rspec include
matcher looks like what I need, but I can't work out how to use it to verify the parameter, or the $allowed_subnets_directives
variable