fuel-library/deployment/puppet/osnailyfacter/spec/functions/setvar_spec.rb
Dmitry Ilyin 6ea79cd733 Add fetch, store and setvar functions
* fetch => get a value from a deeply nested structuure
* store => store a value into a deeply nested structure
* setval => update a valiable in the local scope

Change-Id: Ibf78ae7b3e1b3b1f835558ac20c28fa9d6d1e90e
Related-Blueprint: puppet-helpers-functions
2015-07-14 21:30:27 +03:00

51 lines
1.3 KiB
Ruby

require 'spec_helper'
describe 'the setvar function' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it 'should exist' do
expect(Puppet::Parser::Functions.function('setvar')).to eq 'function_setvar'
end
before(:each) do
scope.function_setvar ['test', 'test']
end
it 'sets the initial test value' do
expect(scope.lookupvar 'test').to eq 'test'
end
it 'can rewrite a variable value' do
scope.function_setvar ['test', '2']
expect(scope.lookupvar 'test').to eq '2'
end
it 'can set a boolean values' do
scope.function_setvar ['test', true]
expect(scope.lookupvar 'test').to eq true
end
it 'can set an Array values' do
scope.function_setvar ['test', ['1','2']]
expect(scope.lookupvar 'test').to eq ['1','2']
end
it 'can set a Hash values' do
scope.function_setvar ['test', {'1' => '2'}]
expect(scope.lookupvar 'test').to eq ({'1' => '2'})
end
it 'can set an Undef value' do
scope.function_setvar ['test', nil]
expect(scope.lookupvar 'test').to eq nil
end
it 'can save non-string values a s string' do
scope.function_setvar ['test', 1]
expect(scope.lookupvar 'test').to eq '1'
scope.function_setvar ['test', :a]
expect(scope.lookupvar 'test').to eq 'a'
end
end