2
我在写一个自定义的puppet模块,其中包含一个:: apache :: vhost资源,并且想验证我的rspec测试中的目录参数是否包含一定的值,而不会重现在spec测试中大部分硬编码的整个目录配置。如何检查数组参数是否包含一个值
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
为了简洁,我已经删除了大部分清单。
我可以测试整个指令参数与沿
describe 'foo::apache' do
it { is_expected.to contain_apache__vhost('foo_vhost').with(
'directories' => [{'path' => '~^.*$',
'allow' => ['from localhost',
'from 10.20.30/24',
],},
]
线的东西,但目录的参数是长和静,和我热衷于避免这种情况。
RSpec的include
匹配看起来像我需要什么,但我不能工作了如何使用它来验证参数,或$allowed_subnets_directives
可变
FWIW,在阵列预先计算的东西一切都可以使用[该regsubst函数]旧版本进行(http://docs.puppetlabs.com/references/stable/function.html#regsubst)。 –