From: Cody Herriges Date: Thu, 12 Apr 2012 00:49:30 +0000 (-0700) Subject: Tests to validate apt::{conf,backports} X-Git-Tag: 0.0.3~10^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=644ed232a0c402b1020b697a10c612db68a9ffa4;p=puppet-modules%2Fpuppetlabs-apt.git 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. --- diff --git a/manifests/backports.pp b/manifests/backports.pp index 6734e05..1526890 100644 --- a/manifests/backports.pp +++ b/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"], } } - diff --git a/manifests/conf.pp b/manifests/conf.pp index 6be1a67..c1af710 100644 --- a/manifests/conf.pp +++ b/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', } } diff --git a/manifests/init.pp b/manifests/init.pp index 5668d11..3ea92ab 100644 --- a/manifests/init.pp +++ b/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, diff --git a/manifests/params.pp b/manifests/params.pp index 79989c0..8e4fa93 100644 --- a/manifests/params.pp +++ b/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' } } } diff --git a/manifests/source.pp b/manifests/source.pp index 3d4011e..204639b 100644 --- a/manifests/source.pp +++ b/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', diff --git a/spec/classes/backports_spec.rb b/spec/classes/backports_spec.rb new file mode 100644 index 0000000..feabef1 --- /dev/null +++ b/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 diff --git a/spec/defines/conf_spec.rb b/spec/defines/conf_spec.rb new file mode 100644 index 0000000..7c04db1 --- /dev/null +++ b/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