]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Convert apt::source to use apt::setting
authorMorgan Haskel <morgan@puppetlabs.com>
Sat, 21 Feb 2015 20:11:57 +0000 (12:11 -0800)
committerMorgan Haskel <morgan@puppetlabs.com>
Sat, 21 Feb 2015 23:26:48 +0000 (15:26 -0800)
May as well use the define since we added it

manifests/source.pp
spec/classes/apt_spec.rb
spec/defines/source_spec.rb

index 0ca52123190d9a06157331e7f38a11c907779415..bbd504e3747e6987bcbc09fa097eb23745ba80b4 100644 (file)
@@ -23,17 +23,13 @@ define apt::source(
     fail('lsbdistcodename fact not available: release parameter required')
   }
 
-  file { "${name}.list":
-    ensure  => $ensure,
-    path    => "${::apt::sources_list_d}/${name}.list",
-    owner   => root,
-    group   => root,
-    mode    => '0644',
-    content => template('apt/_header.erb', 'apt/source.list.erb'),
-    notify  => Exec['apt_update'],
+  apt::setting { $name:
+    ensure       => $ensure,
+    setting_type => 'list',
+    content      => template('apt/_header.erb', 'apt/source.list.erb'),
+    notify       => Exec['apt_update'],
   }
 
-
   if ($pin != false) {
     # Get the host portion out of the url so we can pin to origin
     $url_split = split($location, '/')
@@ -42,7 +38,7 @@ define apt::source(
     apt::pin { $name:
       ensure   => $ensure,
       priority => $pin,
-      before   => File["${name}.list"],
+      before   => Apt::Setting[$name],
       origin   => $host,
     }
   }
@@ -55,7 +51,7 @@ define apt::source(
       key_server  => $key_server,
       key_content => $key_content,
       key_source  => $key_source,
-      before      => File["${name}.list"],
+      before      => Apt::Setting[$name],
     }
   }
 
index d4be96419b98e68014bf2891295747f22361df7c..f8e8c17380eeabf93703de679903ca898de663fd 100644 (file)
@@ -110,31 +110,23 @@ describe 'apt', :type => :class do
     } } }
 
     it {
-      should contain_file('debian_unstable.list').with({
+      should contain_apt__setting('debian_unstable').with({
         'ensure'  => 'present',
-        'path'    => '/etc/apt/sources.list.d/debian_unstable.list',
-        'owner'   => 'root',
-        'group'   => 'root',
-        'mode'    => '0644',
         'notify'  => 'Exec[apt_update]',
       })
     }
 
-    it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
-    it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
+    it { should contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
+    it { should contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
 
     it {
-      should contain_file('puppetlabs.list').with({
+      should contain_apt__setting('puppetlabs').with({
         'ensure'  => 'present',
-        'path'    => '/etc/apt/sources.list.d/puppetlabs.list',
-        'owner'   => 'root',
-        'group'   => 'root',
-        'mode'    => '0644',
         'notify'  => 'Exec[apt_update]',
       })
     }
 
-    it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
+    it { should contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
   end
 
   describe 'failing tests' do
index ff236bd5d01e877f88483fbc3e451eebf2247388..85a6d76043f4ea7389d7008b481a886027150782 100644 (file)
@@ -27,12 +27,8 @@ describe 'apt::source', :type => :define do
       }
     end
 
-    it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
+    it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({
       'ensure' => 'present',
-      'path'   => '/etc/apt/sources.list.d/my_source.list',
-      'owner'  => 'root',
-      'group'  => 'root',
-      'mode'   => '0644',
     }).with_content(/# my_source\ndeb-src  wheezy main\n/)
     }
   end
@@ -62,23 +58,19 @@ describe 'apt::source', :type => :define do
       }
     end
 
-    it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
+    it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({
       'ensure' => 'present',
-      'path'   => '/etc/apt/sources.list.d/my_source.list',
-      'owner'  => 'root',
-      'group'  => 'root',
-      'mode'   => '0644',
     }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/)
     }
 
-    it { is_expected.to contain_apt__pin('my_source').that_comes_before('File[my_source.list]').with({
+    it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[my_source]').with({
       'ensure'   => 'present',
       'priority' => '10',
       'origin'   => 'debian.mirror.iweb.ca',
     })
     }
 
-    it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('File[my_source.list]').with({
+    it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[my_source]').with({
       'ensure' => 'present',
         'key'  => GPG_KEY_ID,
         'key_server' => 'pgp.mit.edu',
@@ -103,12 +95,8 @@ describe 'apt::source', :type => :define do
       }
     end
 
-    it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
+    it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({
       'ensure' => 'present',
-      'path'   => '/etc/apt/sources.list.d/my_source.list',
-      'owner'  => 'root',
-      'group'  => 'root',
-      'mode'   => '0644',
     }).with_content(/# my_source\ndeb \[trusted=yes\]  wheezy main\n/)
     }
   end
@@ -129,12 +117,8 @@ describe 'apt::source', :type => :define do
       }
     end
 
-    it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
+    it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({
       'ensure' => 'present',
-      'path'   => '/etc/apt/sources.list.d/my_source.list',
-      'owner'  => 'root',
-      'group'  => 'root',
-      'mode'   => '0644',
     }).with_content(/# my_source\ndeb-src \[arch=x86_64 \]  wheezy main\n/)
     }
   end
@@ -153,7 +137,7 @@ describe 'apt::source', :type => :define do
       }
     end
 
-    it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({
+    it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({
       'ensure' => 'absent'
     })
     }