diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..6242a37 --- /dev/null +++ b/Rakefile @@ -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 + diff --git a/manifests/ppa.pp b/manifests/ppa.pp index af6eebf..a41c814 100644 --- a/manifests/ppa.pp +++ b/manifests/ppa.pp @@ -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}.*$'", + } } } diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb new file mode 100644 index 0000000..6532654 --- /dev/null +++ b/spec/defines/ppa_spec.rb @@ -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 diff --git a/spec/spec.opts b/spec/spec.opts new file mode 100644 index 0000000..91cd642 --- /dev/null +++ b/spec/spec.opts @@ -0,0 +1,6 @@ +--format +s +--colour +--loadby +mtime +--backtrace diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..d2648da --- /dev/null +++ b/spec/spec_helper.rb @@ -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