|
63 | 63 |
|
64 | 64 | describe 'when passed a defined type' do |
65 | 65 | let :pre_condition do |
66 | | - 'define test::deftype() { } test::deftype { "foo": }' |
| 66 | + <<-PRECOND |
| 67 | + define test::deftype( |
| 68 | + Optional $port = undef |
| 69 | + ) { } |
| 70 | +
|
| 71 | + test::deftype { "foo": } |
| 72 | + test::deftype { "baz": port => 100 } |
| 73 | + test::deftype { "adv": port => 200 } |
| 74 | + test::deftype { "adv2": port => 200 } |
| 75 | +
|
| 76 | + # Unsure how to stub this out below properly |
| 77 | + if defined_with_params(Test::Deftype, { 'port' => 200 }) { |
| 78 | + notify { 'Duplicate found somewhere': } |
| 79 | + } |
| 80 | + if defined_with_params(Test::Deftype, { 'port' => 'nope' }) { |
| 81 | + notify { 'Should not find me': } |
| 82 | + } |
| 83 | + PRECOND |
67 | 84 | end |
68 | 85 |
|
69 | 86 | it { is_expected.to run.with_params('Test::Deftype[foo]', {}).and_return(true) } |
70 | 87 | it { is_expected.to run.with_params('Test::Deftype[bar]', {}).and_return(false) } |
71 | 88 | it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[foo]'), {}).and_return(true) } |
72 | | - it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[bar]'), {}).and_return(false) } |
| 89 | + it { |
| 90 | + is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[bar]'), {}).and_return(false) |
| 91 | + |
| 92 | + expect(catalogue.resource('Notify[Duplicate found somewhere]')).not_to be_nil |
| 93 | + expect(catalogue.resource('Notify[Should not find me]')).to be_nil |
| 94 | + } |
| 95 | + end |
| 96 | + |
| 97 | + describe 'when called from within a defined type looking for a defined type of the same type' do |
| 98 | + let :pre_condition do |
| 99 | + <<-PRECOND |
| 100 | + define test::deftype( |
| 101 | + Optional $port = undef |
| 102 | + ) { |
| 103 | + if defined_with_params(Test::Deftype, { 'port' => $port }) { |
| 104 | + fail('Ruh Roh Shaggy') |
| 105 | + } |
| 106 | + } |
| 107 | +
|
| 108 | + test::deftype { 'foo': } |
| 109 | + test::deftype { 'bar': port => 200 } |
| 110 | + PRECOND |
| 111 | + end |
| 112 | + |
| 113 | + # Testing to make sure that the internal logic handles this case via the pre_condition |
| 114 | + it { is_expected.to run.with_params('NoOp[noop]', {}).and_return(false) } |
73 | 115 | end |
74 | 116 |
|
75 | 117 | describe 'when passed a class' do |
|
0 commit comments