我正在编写一个包含 ::apache::vhost 资源的自定义 puppet 模块,并且想在我的 rspec 测试中验证目录参数是否包含某个值,而不复制在规范测试中大部分是硬编码的整个目录配置.
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',
],},
]
但是目录参数很长而且是静态的,我很想避免这种情况。
rspecinclude
匹配器看起来像我需要的,但我不知道如何使用它来验证参数或$allowed_subnets_directives
变量