Add the FrozenStrings magic comment
[puppet-modules/puppetlabs-apt.git] / spec / defines / key_spec.rb
index 2378d777914415b1636747842a9cc1f76299cb9e..14ea231230f87ff7e704206f85259c8da7f43ab4 100644 (file)
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'spec_helper'
 
 GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'.freeze
@@ -15,7 +17,8 @@ def default_apt_key_example(title)
     source: nil,
     server: 'keyserver.ubuntu.com',
     content: nil,
-    options: nil }
+    options: nil,
+    refresh: false }
 end
 
 def bunch_things_apt_key_example(title, params)
@@ -43,11 +46,10 @@ describe 'apt::key' do
 
   let(:facts) do
     {
-      os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
+      os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
       lsbdistid: 'Debian',
       osfamily: 'Debian',
-      lsbdistcodename: 'wheezy',
-      puppetversion: Puppet.version,
+      lsbdistcodename: 'jessie',
     }
   end
 
@@ -99,6 +101,21 @@ describe 'apt::key' do
       end
     end
 
+    describe 'ensure => refreshed' do
+      let :params do
+        {
+          ensure: 'refreshed',
+        }
+      end
+
+      it 'contains the apt_key with refresh => true' do
+        is_expected.to contain_apt_key(title).with(
+          ensure: 'present',
+          refresh: true,
+        )
+      end
+    end
+
     describe 'set a bunch of things!' do
       let :params do
         {
@@ -276,7 +293,7 @@ describe 'apt::key' do
       end
 
       it 'fails' do
-        is_expected.to raise_error(%r{expects a match})
+        is_expected.to raise_error(%r{evaluating a Resource})
       end
     end
 
@@ -317,7 +334,7 @@ describe 'apt::key' do
     end
 
     context 'with invalid ensure' do
-      ['foo', 'aabsent', 'absenta', 'apresent', 'presenta'].each do |param|
+      ['foo', 'aabsent', 'absenta', 'apresent', 'presenta', 'refresh', 'arefreshed', 'refresheda'].each do |param|
         let :params do
           {
             ensure: param,
@@ -325,7 +342,7 @@ describe 'apt::key' do
         end
 
         it 'fails' do
-          is_expected.to raise_error(%r{for Enum\['absent', 'present'\], got})
+          is_expected.to raise_error(%r{for Enum\['absent', 'present', 'refreshed'\], got})
         end
       end
     end
@@ -364,4 +381,30 @@ describe 'apt::key' do
       end
     end
   end
+
+  describe 'defaults' do
+    context 'when setting keyserver on the apt class' do
+      let :pre_condition do
+        'class { "apt":
+          keyserver => "keyserver.example.com",
+        }'
+      end
+
+      it 'uses default keyserver' do
+        is_expected.to contain_apt_key(title).with_server('keyserver.example.com')
+      end
+    end
+
+    context 'when setting key_options on the apt class' do
+      let :pre_condition do
+        'class { "apt":
+          key_options => "http-proxy=http://proxy.example.com:8080",
+        }'
+      end
+
+      it 'uses default keyserver' do
+        is_expected.to contain_apt_key(title).with_options('http-proxy=http://proxy.example.com:8080')
+      end
+    end
+  end
 end