diff options
author | Ashley Penney <ashley.penney@puppetlabs.com> | 2014-03-05 15:43:58 -0500 |
---|---|---|
committer | Ashley Penney <ashley.penney@puppetlabs.com> | 2014-03-10 10:58:49 -0700 |
commit | dbb29980a170623c578c51c471af71ff66e23e9c (patch) | |
tree | 21bd50f4cf0c5d79efadcc9b8ffab145bbfd3f03 /spec/functions/ensure_resource_spec.rb | |
parent | 326a8fd801ecba11005189c10ca8749872ef6577 (diff) |
Numerous changes to update testing gems.
This work updates a number of Gems to the latest versions (rspec,
rspec-puppet), and updates and tweaks a bunch of tests to work
with the updated gems.
Diffstat (limited to 'spec/functions/ensure_resource_spec.rb')
-rw-r--r-- | spec/functions/ensure_resource_spec.rb | 75 |
1 files changed, 48 insertions, 27 deletions
diff --git a/spec/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb index 611666e..430691c 100644 --- a/spec/functions/ensure_resource_spec.rb +++ b/spec/functions/ensure_resource_spec.rb @@ -1,40 +1,61 @@ -#! /usr/bin/env ruby -S rspec require 'spec_helper' - require 'rspec-puppet' +require 'puppet_spec/compiler' + describe 'ensure_resource' do + include PuppetSpec::Compiler + + before :all do + Puppet::Parser::Functions.autoloader.loadall + Puppet::Parser::Functions.function(:ensure_packages) + end + + let :node do Puppet::Node.new('localhost') end + let :compiler do Puppet::Parser::Compiler.new(node) end + let :scope do Puppet::Parser::Scope.new(compiler) end + describe 'when a type or title is not specified' do - it do - should run.with_params().and_raise_error(ArgumentError) - should run.with_params(['type']).and_raise_error(ArgumentError) - end + it { expect { scope.function_ensure_resource([]) }.to raise_error } + it { expect { scope.function_ensure_resource(['type']) }.to raise_error } end + describe 'when compared against a resource with no attributes' do - let :pre_condition do - 'user { "dan": }' + let :catalog do + compile_to_catalog(<<-EOS + user { "dan": } + ensure_resource('user', 'dan', {}) + EOS + ) end - it do - should run.with_params('user', 'dan', {}) - compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]' + + it 'should contain the the ensured resources' do + expect(catalog.resource(:user, 'dan').to_s).to eq('User[dan]') end end - describe 'when compared against a resource with attributes' do - let :pre_condition do - 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}' - end - it do - # these first three should not fail - should run.with_params('User', 'dan', {}) - should run.with_params('User', 'dan', '') - should run.with_params('User', 'dan', {'ensure' => 'present'}) - should run.with_params('User', 'dan', - {'ensure' => 'present', 'managehome' => false} - ) - # test that this fails - should run.with_params('User', 'dan', - {'ensure' => 'absent', 'managehome' => false} - ).and_raise_error(Puppet::Error) + describe 'works when compared against a resource with non-conflicting attributes' do + [ + "ensure_resource('User', 'dan', {})", + "ensure_resource('User', 'dan', '')", + "ensure_resource('User', 'dan', {'ensure' => 'present'})", + "ensure_resource('User', 'dan', {'ensure' => 'present', 'managehome' => false})" + ].each do |ensure_resource| + pp = <<-EOS + user { "dan": ensure => present, shell => "/bin/csh", managehome => false} + #{ensure_resource} + EOS + + it { expect { compile_to_catalog(pp) }.to_not raise_error } end end + + describe 'fails when compared against a resource with conflicting attributes' do + pp = <<-EOS + user { "dan": ensure => present, shell => "/bin/csh", managehome => false} + ensure_resource('User', 'dan', {'ensure' => 'absent', 'managehome' => false}) + EOS + + it { expect { compile_to_catalog(pp) }.to raise_error } + end + end |