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)。 –