491a03be70d919efffbf88a24f69c97ea0f67d89
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / defined_with_params_spec.rb
1 require 'spec_helper'
2
3 describe 'defined_with_params' do
4   describe 'when no resource is specified' do
5     it { is_expected.to run.with_params().and_raise_error(ArgumentError) }
6   end
7   describe 'when compared against a resource with no attributes' do
8     let :pre_condition do
9       'user { "dan": }'
10     end
11     it { is_expected.to run.with_params('User[dan]', {}).and_return(true) }
12     it { is_expected.to run.with_params('User[bob]', {}).and_return(false) }
13     it { is_expected.to run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false) }
14
15     context 'should run with UTF8 and double byte characters' do
16       it { is_expected.to run.with_params('User[ĵĭмოү]', {}).and_return(false) }
17       it { is_expected.to run.with_params('User[ポーラ]', {}).and_return(false) }
18     end
19   end
20
21   describe 'when compared against a resource with attributes' do
22     let :pre_condition do
23       'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
24     end
25     it { is_expected.to run.with_params('User[dan]', {}).and_return(true) }
26     it { is_expected.to run.with_params('User[dan]', '').and_return(true) }
27     it { is_expected.to run.with_params('User[dan]', {'ensure' => 'present'}).and_return(true) }
28     it { is_expected.to run.with_params('User[dan]', {'ensure' => 'present', 'managehome' => false}).and_return(true) }
29     it { is_expected.to run.with_params('User[dan]', {'ensure' => 'absent', 'managehome' => false}).and_return(false) }
30   end
31
32   describe 'when passing undef values' do
33     let :pre_condition do
34       'file { "/tmp/a": ensure => present }'
35     end
36
37     it { is_expected.to run.with_params('File[/tmp/a]', {}).and_return(true) }
38     it { is_expected.to run.with_params('File[/tmp/a]', { 'ensure' => 'present', 'owner' => :undef }).and_return(true) }
39   end
40
41   describe 'when the reference is a' do
42     let :pre_condition do
43       'user { "dan": }'
44     end
45     context 'reference' do
46       it { is_expected.to run.with_params(Puppet::Resource.new('User[dan]'), {}).and_return(true) }
47     end
48     if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0
49       context 'array' do
50         it 'fails' do
51           expect {
52             subject.call([['User[dan]'], {}])
53           }.to raise_error ArgumentError, /not understood: 'Array'/
54         end
55       end
56     end
57   end
58
59   describe 'when passed a defined type' do
60     let :pre_condition do
61       'test::deftype { "foo": }'
62     end
63     it { is_expected.to run.with_params('Test::Deftype[foo]', {}).and_return(true) }
64     it { is_expected.to run.with_params('Test::Deftype[bar]', {}).and_return(false) }
65     it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[foo]'), {}).and_return(true) }
66     it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[bar]'), {}).and_return(false) }
67   end
68 end