2012-07-20 01:14:37 +02:00
|
|
|
#! /usr/bin/env ruby -S rspec
|
|
|
|
|
|
|
|
require 'spec_helper'
|
2011-07-30 00:28:21 +02:00
|
|
|
|
2012-07-20 01:14:37 +02:00
|
|
|
describe Puppet::Parser::Functions.function(:merge) do
|
2012-07-23 17:28:06 +02:00
|
|
|
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
2011-07-30 00:28:21 +02:00
|
|
|
|
|
|
|
describe 'when calling merge from puppet' do
|
|
|
|
it "should not compile when no arguments are passed" do
|
2012-08-10 20:43:36 +02:00
|
|
|
pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
|
2012-08-09 23:18:30 +02:00
|
|
|
Puppet[:code] = '$x = merge()'
|
|
|
|
expect {
|
|
|
|
scope.compiler.compile
|
|
|
|
}.to raise_error(Puppet::ParseError, /wrong number of arguments/)
|
2011-07-30 00:28:21 +02:00
|
|
|
end
|
2012-08-10 20:43:36 +02:00
|
|
|
|
2011-07-30 00:28:21 +02:00
|
|
|
it "should not compile when 1 argument is passed" do
|
2012-08-10 20:43:36 +02:00
|
|
|
pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
|
2012-08-09 23:18:30 +02:00
|
|
|
Puppet[:code] = "$my_hash={'one' => 1}\n$x = merge($my_hash)"
|
|
|
|
expect {
|
|
|
|
scope.compiler.compile
|
|
|
|
}.to raise_error(Puppet::ParseError, /wrong number of arguments/)
|
2011-07-30 00:28:21 +02:00
|
|
|
end
|
|
|
|
end
|
2012-08-10 20:43:36 +02:00
|
|
|
|
2011-07-30 00:28:21 +02:00
|
|
|
describe 'when calling merge on the scope instance' do
|
|
|
|
it 'should require all parameters are hashes' do
|
2012-10-16 12:54:14 +02:00
|
|
|
expect { new_hash = scope.function_merge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/)
|
2011-07-30 00:28:21 +02:00
|
|
|
end
|
2012-08-10 20:43:36 +02:00
|
|
|
|
2011-07-30 00:28:21 +02:00
|
|
|
it 'should be able to merge two hashes' do
|
|
|
|
new_hash = scope.function_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}])
|
|
|
|
new_hash['one'].should == '1'
|
|
|
|
new_hash['two'].should == '2'
|
|
|
|
new_hash['three'].should == '2'
|
|
|
|
end
|
2012-08-10 20:43:36 +02:00
|
|
|
|
2011-07-30 00:28:21 +02:00
|
|
|
it 'should merge multiple hashes' do
|
|
|
|
hash = scope.function_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}])
|
|
|
|
hash['one'].should == '3'
|
|
|
|
end
|
2012-08-10 20:43:36 +02:00
|
|
|
|
2011-07-30 00:28:21 +02:00
|
|
|
it 'should accept empty hashes' do
|
|
|
|
scope.function_merge([{},{},{}]).should == {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|