Browse Source

Tests to validate apt::{conf,backports}

  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.
Cody Herriges 12 years ago
parent
commit
644ed232a0

+ 5 - 4
manifests/backports.pp

@@ -23,12 +23,14 @@
 # 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"],
   }
 }
-

+ 3 - 3
manifests/conf.pp

@@ -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',
   }
 }

+ 1 - 1
manifests/init.pp

@@ -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,

+ 2 - 2
manifests/params.pp

@@ -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'
         }
       }
     }

+ 1 - 1
manifests/source.pp

@@ -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',

+ 74 - 0
spec/classes/backports_spec.rb

@@ -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

+ 34 - 0
spec/defines/conf_spec.rb

@@ -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