]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Tests to validate apt::{conf,backports}
authorCody Herriges <c.a.herriges@gmail.com>
Thu, 12 Apr 2012 00:49:30 +0000 (17:49 -0700)
committerCody Herriges <c.a.herriges@gmail.com>
Fri, 20 Apr 2012 20:43:38 +0000 (13:43 -0700)
  This patch adds the appropriate spec tests to validate the changes
  introduced by e5f2dfe.  As a bonus it includes fixes to the manifests
  that were discovered while writing the tests.

manifests/backports.pp
manifests/conf.pp
manifests/init.pp
manifests/params.pp
manifests/source.pp
spec/classes/backports_spec.rb [new file with mode: 0644]
spec/defines/conf_spec.rb [new file with mode: 0644]

index 6734e05297629cfad9d91b4643b45d629c5da47a..152689055c70569dd1ca9aabb1e5c1c937d47324 100644 (file)
 # Copyright 2011 Puppet Labs Inc, unless otherwise noted.
 class apt::backports(
   $release  = $lsbdistcodename,
-  $location = $apt::params::backports_locations
+  $location = $apt::params::backports_location
 ) inherits apt::params {
 
+  $release_real = downcase($release)
+
   apt::source { 'backports.list':
     location   => $location,
-    release    => "${release}-backports",
+    release    => "${release_real}-backports",
     repos      => $lsbdistid ? {
       'debian' => 'main contrib non-free',
       'ubuntu' => 'universe multiverse restricted',
@@ -39,7 +41,6 @@ class apt::backports(
     },
     key_server => 'pgp.mit.edu',
     pin        => '200',
-    notify => Exec["apt-get update"],
+    notify => Exec["apt_update"],
   }
 }
-
index 6be1a67facd423c919615aea0c26997d57236021..c1af710fd4b2a3b45f92f830a7eafeab27464935 100644 (file)
@@ -5,13 +5,13 @@ define apt::conf (
 
   include apt::params
 
-  $root       = "${apt::params::root}"
-  $apt_conf_d = "${apt::params::apt_conf_d}"
+  $apt_conf_d = $apt::params::apt_conf_d
 
   file { "${apt_conf_d}/${priority}${name}":
+    ensure  => file,
     content => $content,
     owner   => root,
     group   => root,
-    mode    => 0644,
+    mode    => '0644',
   }
 }
index 5668d110059d0b82afca2b026e700463e4b86c61..3ea92ab1bfa584d0ce0ce83c0e7c5692f7437b7f 100644 (file)
@@ -62,7 +62,7 @@ class apt(
 
   file { 'sources.list.d':
     ensure  => directory,
-    path    => $sources_list_d
+    path    => $sources_list_d,
     owner   => root,
     group   => root,
     purge   => $purge_sources_list_d,
index 79989c08a45f57c3566c0b50499070f54bff76ca..8e4fa932b17cbe873daef887f9c7df69e1df8b9d 100644 (file)
@@ -12,10 +12,10 @@ class apt::params {
     'ubuntu': {
       case $lsbdistcodename {
         'hardy','lucid','maverick','natty','oneiric','precise': {
-          $backports_location = http://us.archive.ubuntu.com/ubuntuk
+          $backports_location = 'http://us.archive.ubuntu.com/ubuntu'
         }
         default: {
-          $backports_location = 'http://old-releases.ubuntu.com/ubuntu',
+          $backports_location = 'http://old-releases.ubuntu.com/ubuntu'
         }
       }
     }
index 3d4011e26dda5bb352410bbc9d7720dfa3119737..204639bdc5734547a5a7710f85af0a9d70c9cff8 100644 (file)
@@ -25,7 +25,7 @@ define apt::source(
 
   file { "${name}.list":
     ensure  => file,
-    path    => "${apt::params::sources_list_d}/${name}.list",
+    path    => "${sources_list_d}/${name}.list",
     owner   => root,
     group   => root,
     mode    => '0644',
diff --git a/spec/classes/backports_spec.rb b/spec/classes/backports_spec.rb
new file mode 100644 (file)
index 0000000..feabef1
--- /dev/null
@@ -0,0 +1,74 @@
+require 'spec_helper'
+describe 'apt::backports', :type => :class do
+
+  describe 'when turning on backports for ubuntu karmic' do
+
+    let :facts do
+      {
+        'lsbdistcodename' => 'Karmic',
+        'lsbdistid'       => 'Ubuntu'
+      }
+    end
+
+    it { should contain_apt__source('backports.list').with({
+        'location'   => 'http://old-releases.ubuntu.com/ubuntu',
+        'release'    => 'karmic-backports',
+        'repos'      => 'universe multiverse restricted',
+        'key'        => '437D05B5',
+        'key_server' => 'pgp.mit.edu',
+        'pin'        => '200',
+        'notify'     => 'Exec[apt_update]'
+      })
+    }
+  end
+
+  describe "when turning on backports for debian squeeze" do
+
+    let :facts do
+      {
+        'lsbdistcodename' => 'Squeeze',
+        'lsbdistid'       => 'Debian',
+      }
+    end
+
+    it { should contain_apt__source('backports.list').with({
+        'location'   => 'http://backports.debian.org/debian-backports',
+        'release'    => 'squeeze-backports',
+        'repos'      => 'main contrib non-free',
+        'key'        => '55BE302B',
+        'key_server' => 'pgp.mit.edu',
+        'pin'        => '200',
+        'notify'     => 'Exec[apt_update]'
+      })
+    }
+  end
+
+  describe "when turning on backports for debian squeeze but using your own mirror" do
+
+    let :facts do
+      {
+        'lsbdistcodename' => 'Squeeze',
+        'lsbdistid'       => 'Debian'
+      }
+    end
+
+    let :location do
+      'http://mirrors.example.com/debian-backports'
+    end
+
+    let :params do
+      { 'location' => location }
+    end
+
+    it { should contain_apt__source('backports.list').with({
+        'location'   => location,
+        'release'    => 'squeeze-backports',
+        'repos'      => 'main contrib non-free',
+        'key'        => '55BE302B',
+        'key_server' => 'pgp.mit.edu',
+        'pin'        => '200',
+        'notify'     => 'Exec[apt_update]'
+      })
+    }
+  end
+end
diff --git a/spec/defines/conf_spec.rb b/spec/defines/conf_spec.rb
new file mode 100644 (file)
index 0000000..7c04db1
--- /dev/null
@@ -0,0 +1,34 @@
+require 'spec_helper'
+describe 'apt::conf', :type => :define do
+  let :title do
+    'norecommends'
+  end
+
+  describe "when creating an apt preference" do
+    let :params do
+      {
+        :priority => '00',
+        :content  => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
+      }
+    end
+
+    let :filename do
+      "/etc/apt/apt.conf.d/00norecommends"
+    end
+
+    it { should contain_apt__conf('norecommends').with({
+         'priority' => '00',
+         'content'  => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
+      })
+    }
+
+    it { should contain_file(filename).with({
+          'ensure'    => 'file',
+          'content'   => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
+          'owner'     => 'root',
+          'group'     => 'root',
+          'mode'      => '0644',
+        })
+      }
+  end
+end