Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

(#14841) Add test for hiera_hash parser function

This required pulling in the puppetlabs_spec_helper, since the parser
functions depend on puppet being somewhat configured.
  • Loading branch information...
commit d76a9d87547a12a41c4ac4fefe234f996e85dab6 1 parent 7a458a4
@pcarlisle pcarlisle authored
View
1  Rakefile
@@ -1,6 +1,7 @@
require 'rubygems'
require 'rubygems/package_task'
require 'rspec/core/rake_task'
+require 'puppetlabs_spec_helper/rake_tasks'
Dir['tasks/**/*.rake'].each { |t| load t }
View
1  spec/spec_helper.rb
@@ -2,6 +2,7 @@
require 'rubygems'
require 'rspec'
+require 'puppetlabs_spec_helper/module_spec_helper'
require 'hiera/backend/puppet_backend'
require 'hiera/scope'
require 'rspec/mocks'
View
13 spec/unit/parser/functions/hiera_hash_spec.rb
@@ -3,9 +3,20 @@
require 'spec_helper'
describe 'Puppet::Parser::Functions#hiera_hash' do
- it 'should require a key argument' do
+ before do
Puppet::Parser::Functions.function(:hiera_hash)
@scope = Puppet::Parser::Scope.new
+ configfile = File.join(File.dirname(Puppet.settings[:config]), "hiera.yaml")
+ File.stubs(:exist?).with(configfile).returns true
+ YAML.stubs(:load_file).with(configfile).returns(Hash.new)
+ end
+
+ it 'should require a key argument' do
expect { @scope.function_hiera_hash([]) }.should raise_error(Puppet::ParseError)
end
+
+ it 'should raise a useful error when nil is returned' do
+ Hiera.any_instance.expects(:lookup).returns(nil)
+ expect { @scope.function_hiera_hash("badkey") }.should raise_error(Puppet::ParseError, /Could not find data item badkey/ )
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.