Fix regexp for $ensure params

/\Aabsent|present\Z/ match wrong values like 'absentaaa' or 'aaapresent'.

And add tests to the context of 'invalid ensure'.
This commit is contained in:
OKUMURA Takahiro 2016-06-05 03:09:31 +09:00
parent 797974c0a2
commit 459f515879
2 changed files with 10 additions and 8 deletions

View file

@ -49,7 +49,7 @@ define apt::key (
} }
validate_re($_id, ['\A(0x)?[0-9a-fA-F]{8}\Z', '\A(0x)?[0-9a-fA-F]{16}\Z', '\A(0x)?[0-9a-fA-F]{40}\Z']) validate_re($_id, ['\A(0x)?[0-9a-fA-F]{8}\Z', '\A(0x)?[0-9a-fA-F]{16}\Z', '\A(0x)?[0-9a-fA-F]{40}\Z'])
validate_re($ensure, ['\Aabsent|present\Z',]) validate_re($ensure, ['\A(absent|present)\Z',])
if $_content { if $_content {
validate_string($_content) validate_string($_content)

View file

@ -268,15 +268,17 @@ describe 'apt::key' do
end end
context 'invalid ensure' do context 'invalid ensure' do
%w(foo aabsent absenta apresent presenta).each do |param|
let :params do let :params do
{ {
:ensure => 'foo', :ensure => param,
} }
end end
it 'fails' do it 'fails' do
expect { subject.call }.to raise_error(/does not match/) expect { subject.call }.to raise_error(/does not match/)
end end
end end
end
describe 'duplication' do describe 'duplication' do
context 'two apt::key resources for same key, different titles' do context 'two apt::key resources for same key, different titles' do