2012-07-20 01:14:37 +02:00
|
|
|
#! /usr/bin/env ruby -S rspec
|
2011-06-22 02:02:22 +02:00
|
|
|
|
2012-07-20 01:14:37 +02:00
|
|
|
require 'spec_helper'
|
2011-06-22 02:02:22 +02:00
|
|
|
|
|
|
|
describe Puppet::Parser::Functions.function(:validate_hash) do
|
2012-07-23 17:28:06 +02:00
|
|
|
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
2011-06-22 02:02:22 +02:00
|
|
|
|
|
|
|
describe 'when calling validate_hash from puppet' do
|
|
|
|
|
|
|
|
%w{ true false }.each do |the_string|
|
|
|
|
|
|
|
|
it "should not compile when #{the_string} is a string" do
|
|
|
|
Puppet[:code] = "validate_hash('#{the_string}')"
|
2012-07-20 01:14:37 +02:00
|
|
|
expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a Hash/)
|
2011-06-22 02:02:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not compile when #{the_string} is a bare word" do
|
|
|
|
Puppet[:code] = "validate_hash(#{the_string})"
|
2012-07-20 01:14:37 +02:00
|
|
|
expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a Hash/)
|
2011-06-22 02:02:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should compile when multiple hash arguments are passed" do
|
|
|
|
Puppet[:code] = <<-'ENDofPUPPETcode'
|
|
|
|
$foo = {}
|
|
|
|
$bar = { 'one' => 'two' }
|
|
|
|
validate_hash($foo, $bar)
|
|
|
|
ENDofPUPPETcode
|
2012-07-20 01:14:37 +02:00
|
|
|
scope.compiler.compile
|
2011-06-22 02:02:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not compile when an undef variable is passed" do
|
|
|
|
Puppet[:code] = <<-'ENDofPUPPETcode'
|
|
|
|
$foo = undef
|
|
|
|
validate_hash($foo)
|
|
|
|
ENDofPUPPETcode
|
2012-07-20 01:14:37 +02:00
|
|
|
expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a Hash/)
|
2011-06-22 02:02:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|