Update puppetlabs/stdlib module
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / getvar_spec.rb
1 require 'spec_helper'
2
3 describe 'getvar' do
4   it { is_expected.not_to eq(nil) }
5
6   describe 'before Puppet 6.0.0', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do
7     it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
8     it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
9   end
10
11   describe 'from Puppet 6.0.0', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') >= 0 do
12     it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{expects between 1 and 2 arguments, got none}i) }
13     it { is_expected.to run.with_params('one', 'two').and_return('two') }
14     it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(ArgumentError, %r{expects between 1 and 2 arguments, got 3}i) }
15   end
16
17   it { is_expected.to run.with_params('::foo').and_return(nil) }
18
19   context 'with given variables in namespaces' do
20     let(:pre_condition) do
21       <<-PUPPETCODE
22       class site::data { $foo = 'baz' }
23       include site::data
24       PUPPETCODE
25     end
26
27     it { is_expected.to run.with_params('site::data::foo').and_return('baz') }
28     it { is_expected.to run.with_params('::site::data::foo').and_return('baz') }
29     it { is_expected.to run.with_params('::site::data::bar').and_return(nil) }
30   end
31
32   context 'with given variables in namespaces' do
33     let(:pre_condition) do
34       <<-PUPPETCODE
35       class site::info { $lock = 'ŧҺîš íš ắ śţřĭŋĝ' }
36       class site::new { $item = '万Ü€‰' }
37       include site::info
38       include site::new
39       PUPPETCODE
40     end
41
42     it { is_expected.to run.with_params('site::info::lock').and_return('ŧҺîš íš ắ śţřĭŋĝ') }
43     it { is_expected.to run.with_params('::site::new::item').and_return('万Ü€‰') }
44   end
45 end