]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Fix regexp for $ensure params
authorOKUMURA Takahiro <hfm.garden@gmail.com>
Sat, 4 Jun 2016 18:09:31 +0000 (03:09 +0900)
committerOKUMURA Takahiro <hfm.garden@gmail.com>
Sun, 5 Jun 2016 09:44:25 +0000 (18:44 +0900)
/\Aabsent|present\Z/ match wrong values like 'absentaaa' or 'aaapresent'.

And add tests to the context of 'invalid ensure'.

manifests/key.pp
spec/defines/key_spec.rb

index 8fbb47abd0b846aa9fd4ef47a6b46c60e73df1f4..914ec88ca4e92f1861899a76c33cd7938b6e76de 100644 (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($ensure, ['\Aabsent|present\Z',])
+  validate_re($ensure, ['\A(absent|present)\Z',])
 
   if $_content {
     validate_string($_content)
index d4a85a4150e1bd8559931377e2f80a9bdc4d5698..14a3efbc5aadbfeb8527c48b858ca4b39b6f3848 100644 (file)
@@ -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