Skip to content

Commit

Permalink
Fix regexp for $ensure params
Browse files Browse the repository at this point in the history
/\Aabsent|present\Z/ match wrong values like 'absentaaa' or 'aaapresent'.

And add tests to the context of 'invalid ensure'.
  • Loading branch information
hfm committed Jun 5, 2016
1 parent 797974c commit 459f515
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion manifests/key.pp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
}

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 {
validate_string($_content)
Expand Down
16 changes: 9 additions & 7 deletions spec/defines/key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,15 @@
end

context 'invalid ensure' do
let :params do
{
:ensure => 'foo',
}
end
it 'fails' do
expect { subject.call }.to raise_error(/does not match/)
%w(foo aabsent absenta apresent presenta).each do |param|
let :params do
{
:ensure => param,
}
end
it 'fails' do
expect { subject.call }.to raise_error(/does not match/)
end
end
end

Expand Down

0 comments on commit 459f515

Please sign in to comment.