summaryrefslogtreecommitdiff
path: root/spec/functions
diff options
context:
space:
mode:
authorJeff McCune <jeff@puppetlabs.com>2012-11-27 16:19:52 -0800
committerJeff McCune <jeff@puppetlabs.com>2012-11-27 16:19:52 -0800
commit965245eb9755374a3f7d94f2f2b2172e024234c0 (patch)
treeee2eeae9a34c7efa988eeb01bf03d508d13f5778 /spec/functions
parent6f76d8dfd179d3beb73bf69d1ce31411ba3f12ed (diff)
parentdbe3c8ecf6379963f583ea11e51e403e5ad55002 (diff)
Merge branch 'metcalfc/2.x/ensure_packages' into 2.x
* metcalfc/2.x/ensure_packages: (Maint) Add spec/functions to rake test task Add example behaviors for ensure_packages() function Add an ensure_packages function.
Diffstat (limited to 'spec/functions')
-rw-r--r--spec/functions/ensure_packages_spec.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb
new file mode 100644
index 0000000..1c2a328
--- /dev/null
+++ b/spec/functions/ensure_packages_spec.rb
@@ -0,0 +1,42 @@
+#! /usr/bin/env ruby
+
+require 'spec_helper'
+require 'rspec-puppet'
+
+describe 'ensure_packages' do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ describe 'argument handling' do
+ it 'fails with no arguments' do
+ should run.with_params().and_raise_error(Puppet::ParseError)
+ end
+ it 'requires an array' do
+ lambda { scope.function_ensure_packages([['foo']]) }.should_not raise_error
+ end
+ it 'fails when given a string' do
+ should run.with_params('foo').and_raise_error(Puppet::ParseError)
+ end
+ end
+
+ context 'given a catalog containing Package[puppet]{ensure => absent}' do
+ let :pre_condition do
+ 'package { puppet: ensure => absent }'
+ end
+
+ # NOTE: should run.with_params has the side effect of making the compiler
+ # available to the test harness.
+ it 'has no effect on Package[puppet]' do
+ should run.with_params(['puppet'])
+ rsrc = compiler.catalog.resource('Package[puppet]')
+ rsrc.to_hash.should == {:ensure => "absent"}
+ end
+ end
+
+ context 'given a clean catalog' do
+ it 'declares package resources with ensure => present' do
+ should run.with_params(['facter'])
+ rsrc = compiler.catalog.resource('Package[facter]')
+ rsrc.to_hash.should == {:name => "facter", :ensure => "present"}
+ end
+ end
+end