Merge pull request #9 from bodepd/10451_fix_apt_update_refresh

10451 fix apt update refresh
This commit is contained in:
Matthaus Litteken 2012-01-04 10:30:31 -08:00
commit ee5d762351
5 changed files with 67 additions and 7 deletions

14
Rakefile Normal file
View file

@ -0,0 +1,14 @@
require 'rake'
task :default => [:spec]
desc "Run all module spec tests (Requires rspec-puppet gem)"
task :spec do
system("rspec spec/**/*_spec.rb")
end
desc "Build package"
task :build do
system("puppet-module build")
end

View file

@ -4,13 +4,6 @@ define apt::ppa() {
Class['apt'] -> Apt::Ppa[$title]
Exec {
unless => $name? {
/ppa:(.*)/ => "/bin/cat /etc/apt/sources.list /etc/apt/sources.list.d/* | /bin/egrep '^[^#].*ppa.*$1.*$'",
default => "/bin/cat /etc/apt/sources.list /etc/apt/sources.list.d/* | /bin/egrep '^[^#].*${title}.*$'",
}
}
exec { "apt-update-${name}":
command => "/usr/bin/aptitude update",
refreshonly => true,
@ -19,6 +12,10 @@ define apt::ppa() {
exec { "add-apt-repository-${name}":
command => "/usr/bin/add-apt-repository ${name}",
notify => Exec["apt-update-${name}"],
unless => $name? {
/ppa:(.*)/ => "/bin/cat /etc/apt/sources.list /etc/apt/sources.list.d/* | /bin/egrep '^[^#].*ppa.*$1.*$'",
default => "/bin/cat /etc/apt/sources.list /etc/apt/sources.list.d/* | /bin/egrep '^[^#].*${title}.*$'",
}
}
}

32
spec/defines/ppa_spec.rb Normal file
View file

@ -0,0 +1,32 @@
require 'spec_helper'
describe 'apt::ppa', :type => :define do
['ppa:dans_ppa', 'dans_ppa'].each do |t|
describe "with title #{t}" do
let :pre_condition do
'class { "apt": }'
end
let :title do
t
end
let :unless_statement do
if t =~ /ppa:(.*)/
/^[^#].*ppa.*#{$1}.*$/
else
/^[^#].*#{t}.*$/
end
end
it { should contain_exec("add-apt-repository-#{t}").with(
'command' => "/usr/bin/add-apt-repository #{t}",
'notify' => "Exec[apt-update-#{t}]"
)
}
it { should contain_exec("add-apt-repository-#{t}").with_unless(unless_statement) }
it { should contain_exec("apt-update-#{t}").with(
'command' => '/usr/bin/aptitude update',
'refreshonly' => true
)
}
it { should contain_exec("apt-update-#{t}").without_unless }
end
end
end

6
spec/spec.opts Normal file
View file

@ -0,0 +1,6 @@
--format
s
--colour
--loadby
mtime
--backtrace

11
spec/spec_helper.rb Normal file
View file

@ -0,0 +1,11 @@
require 'puppet'
require 'rubygems'
require 'rspec-puppet'
def param_value(subject, type, title, param)
subject.resource(type, title).send(:parameters)[param.to_sym]
end
RSpec.configure do |c|
c.module_path = File.join(File.dirname(__FILE__), '../../')
end