From: Dan Bode Date: Wed, 4 Jan 2012 01:03:24 +0000 (-0800) Subject: (#10451) Add test coverage to apt::ppa X-Git-Tag: 0.0.1~19^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=cf6caa1f15f279f306950ec44456c127649ca179;p=puppet-modules%2Fpuppetlabs-apt.git (#10451) Add test coverage to apt::ppa This commit adds test coverage for apt::ppa. This test coverage is suficient to verify the code changes that resolve the issue with aptitude update not being called when ppas were added (#10451). --- 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/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