]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
(#10451) Add test coverage to apt::ppa
authorDan Bode <dan@puppetlabs.com>
Wed, 4 Jan 2012 01:03:24 +0000 (17:03 -0800)
committerDan Bode <dan@puppetlabs.com>
Wed, 4 Jan 2012 01:03:24 +0000 (17:03 -0800)
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).

Rakefile [new file with mode: 0644]
spec/defines/ppa_spec.rb [new file with mode: 0644]
spec/spec.opts [new file with mode: 0644]
spec/spec_helper.rb [new file with mode: 0644]

diff --git a/Rakefile b/Rakefile
new file mode 100644 (file)
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 (file)
index 0000000..6532654
--- /dev/null
@@ -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 (file)
index 0000000..91cd642
--- /dev/null
@@ -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 (file)
index 0000000..d2648da
--- /dev/null
@@ -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