From 459f5158795c25056306a7f51f1cf265bce6895e Mon Sep 17 00:00:00 2001 From: OKUMURA Takahiro Date: Sun, 5 Jun 2016 03:09:31 +0900 Subject: [PATCH] Fix regexp for $ensure params /\Aabsent|present\Z/ match wrong values like 'absentaaa' or 'aaapresent'. And add tests to the context of 'invalid ensure'. --- manifests/key.pp | 2 +- spec/defines/key_spec.rb | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/manifests/key.pp b/manifests/key.pp index 8fbb47a..914ec88 100644 --- a/manifests/key.pp +++ b/manifests/key.pp @@ -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($ensure, ['\Aabsent|present\Z',]) + validate_re($ensure, ['\A(absent|present)\Z',]) if $_content { validate_string($_content) diff --git a/spec/defines/key_spec.rb b/spec/defines/key_spec.rb index d4a85a4..14a3efb 100644 --- a/spec/defines/key_spec.rb +++ b/spec/defines/key_spec.rb @@ -268,13 +268,15 @@ describe 'apt::key' do 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 -- 2.32.3