Add type to validate policy hash input
Change-Id: Ida6b362c6e7ce21aad2789401e676eeb1542eb5e
This commit is contained in:
parent
9351c2ee7e
commit
1a1b7cc080
@ -53,7 +53,7 @@
|
||||
#
|
||||
define openstacklib::policy (
|
||||
Stdlib::Absolutepath $policy_path = $name,
|
||||
Hash $policies = {},
|
||||
Openstacklib::Policies $policies = {},
|
||||
$file_mode = '0640',
|
||||
$file_user = undef,
|
||||
$file_group = undef,
|
||||
|
36
spec/type_aliases/policies_spec.rb
Normal file
36
spec/type_aliases/policies_spec.rb
Normal file
@ -0,0 +1,36 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'Openstacklib::Policies' do
|
||||
describe 'valid types' do
|
||||
context 'with valid types' do
|
||||
[
|
||||
{},
|
||||
{'name' => {'key' => 'mykey', 'value' => 'myvalue'}},
|
||||
{'name' => {'value' => 'myvalue'}},
|
||||
].each do |value|
|
||||
describe value.inspect do
|
||||
it { is_expected.to allow_value(value) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'invalid types' do
|
||||
context 'with garbage inputs' do
|
||||
[
|
||||
{'name' => {}},
|
||||
{'name' => {'key' => 'mykey'}},
|
||||
{'name' => {'key' => 1, 'value' => 'myvalue'}},
|
||||
{'name' => {'key' => 'mykey', 'value' => 1}},
|
||||
{'name' => {'key' => 'mykey', 'value' => 'myvalue', 'foo' => 'bar'}},
|
||||
{'name' => {'value' => 'myvalue', 'foo' => 'bar'}},
|
||||
{0 => {'key' => 1, 'value' => 'myvalue'}},
|
||||
].each do |value|
|
||||
describe value.inspect do
|
||||
it { is_expected.not_to allow_value(value) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
8
types/policies.pp
Normal file
8
types/policies.pp
Normal file
@ -0,0 +1,8 @@
|
||||
type Openstacklib::Policies = Hash[
|
||||
String[1], Struct[
|
||||
{
|
||||
key => Optional[String[1]],
|
||||
value => String[1],
|
||||
}
|
||||
]
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user