|
1 |
| -require 'spec_helper' |
2 | 1 | require 'open3'
|
| 2 | +require 'spec_helper' |
| 3 | +require 'tempfile' |
3 | 4 |
|
4 | 5 | RSpec.describe 'a type with composite namevars' do
|
5 | 6 | let(:common_args) { '--verbose --trace --debug --strict=error --modulepath spec/fixtures' }
|
|
8 | 9 | it 'is returns the values correctly' do
|
9 | 10 | stdout_str, status = Open3.capture2e("puppet resource #{common_args} composite_namevar")
|
10 | 11 | expect(stdout_str.strip).to match %r{^composite_namevar}
|
| 12 | + expect(stdout_str.strip).to match %r{Looking for \[\]} |
11 | 13 | expect(status).to eq 0
|
12 | 14 | end
|
13 | 15 | it 'returns the required resource correctly' do
|
|
16 | 18 | expect(stdout_str.strip).to match %r{ensure\s*=> \'present\'}
|
17 | 19 | expect(stdout_str.strip).to match %r{package\s*=> \'php\'}
|
18 | 20 | expect(stdout_str.strip).to match %r{manager\s*=> \'yum\'}
|
| 21 | + expect(stdout_str.strip).to match %r{Looking for \[\]} |
19 | 22 | expect(status.exitstatus).to eq 0
|
20 | 23 | end
|
21 |
| - it 'Throws error if title is not a matching title_pattern' do |
22 |
| - stdout_str, status = Open3.capture2e("puppet resource #{common_args} composite_namevar php package=php manager=yum") |
23 |
| - expect(stdout_str.strip).to match %r{No set of title patterns matched the title "php"} |
| 24 | + it 'throws error if title is not a matching title_pattern' do |
| 25 | + stdout_str, status = Open3.capture2e("puppet resource #{common_args} composite_namevar php123 package=php manager=yum") |
| 26 | + expect(stdout_str.strip).to match %r{No set of title patterns matched the title "php123"} |
| 27 | + expect(stdout_str.strip).not_to match %r{Looking for} |
24 | 28 | expect(status.exitstatus).to eq 1
|
25 | 29 | end
|
26 | 30 | it 'returns the match if alternative title_pattern matches' do
|
27 | 31 | stdout_str, status = Open3.capture2e("puppet resource #{common_args} composite_namevar php/gem")
|
28 | 32 | expect(stdout_str.strip).to match %r{^composite_namevar \{ \'php/gem\'}
|
29 | 33 | expect(stdout_str.strip).to match %r{ensure\s*=> \'present\'}
|
| 34 | + expect(stdout_str.strip).to match %r{Looking for \["php/gem"\]} |
30 | 35 | expect(status.exitstatus).to eq 0
|
31 | 36 | end
|
32 | 37 | it 'properly identifies an absent resource if only the title is provided' do
|
33 | 38 | stdout_str, status = Open3.capture2e("puppet resource #{common_args} composite_namevar php-wibble")
|
34 | 39 | expect(stdout_str.strip).to match %r{^composite_namevar \{ \'php-wibble\'}
|
35 | 40 | expect(stdout_str.strip).to match %r{ensure\s*=> \'absent\'}
|
| 41 | + expect(stdout_str.strip).to match %r{Looking for \["php-wibble"\]} |
36 | 42 | expect(status.exitstatus).to eq 0
|
37 | 43 | end
|
38 | 44 | it 'creates a previously absent resource' do
|
|
41 | 47 | expect(stdout_str.strip).to match %r{ensure\s*=> \'present\'}
|
42 | 48 | expect(stdout_str.strip).to match %r{package\s*=> \'php\'}
|
43 | 49 | expect(stdout_str.strip).to match %r{manager\s*=> \'wibble\'}
|
| 50 | + expect(stdout_str.strip).to match %r{Looking for \["php-wibble"\]} |
44 | 51 | expect(status.exitstatus).to eq 0
|
45 | 52 | end
|
46 | 53 | it 'will remove an existing resource' do
|
|
49 | 56 | expect(stdout_str.strip).to match %r{package\s*=> \'php\'}
|
50 | 57 | expect(stdout_str.strip).to match %r{manager\s*=> \'gem\'}
|
51 | 58 | expect(stdout_str.strip).to match %r{ensure\s*=> \'absent\'}
|
| 59 | + expect(stdout_str.strip).to match %r{Looking for \["php-gem"\]} |
52 | 60 | expect(status.exitstatus).to eq 0
|
53 | 61 | end
|
54 | 62 | end
|
55 | 63 |
|
56 | 64 | describe 'using `puppet apply`' do
|
57 |
| - require 'tempfile' |
58 |
| - |
59 | 65 | let(:common_args) { super() + ' --detailed-exitcodes' }
|
60 | 66 |
|
61 |
| - # run Open3.capture2e only once to get both output, and exitcode # rubocop:disable RSpec/InstanceVariable |
| 67 | + # run Open3.capture2e only once to get both output, and exitcode |
| 68 | + # rubocop:disable RSpec/InstanceVariable |
62 | 69 | before(:each) do
|
63 | 70 | Tempfile.create('acceptance') do |f|
|
64 | 71 | f.write(manifest)
|
|
67 | 74 | end
|
68 | 75 | end
|
69 | 76 |
|
70 |
| - context 'when managing a present instance' do |
71 |
| - let(:manifest) { 'composite_namevar { php-gem: }' } |
| 77 | + context 'when matching title patterns' do |
| 78 | + context 'when managing a present instance' do |
| 79 | + let(:manifest) { 'composite_namevar { php-gem: }' } |
72 | 80 |
|
73 |
| - it { expect(@stdout_str).to match %r{Current State: \{:title=>"php-gem", :package=>"php", :manager=>"gem", :ensure=>"present", :value=>"b"\}} } |
74 |
| - it { expect(@status.exitstatus).to eq 0 } |
75 |
| - end |
| 81 | + it { expect(@stdout_str).to match %r{Current State: \{:title=>"php-gem", :package=>"php", :manager=>"gem", :ensure=>"present", :value=>"b"\}} } |
| 82 | + it { expect(@stdout_str).to match %r{Looking for \["php-gem"\]} } |
| 83 | + it { expect(@status.exitstatus).to eq 0 } |
| 84 | + end |
76 | 85 |
|
77 |
| - context 'when managing an absent instance' do |
78 |
| - let(:manifest) { 'composite_namevar { php-wibble: ensure=>\'absent\' }' } |
| 86 | + context 'when managing an absent instance' do |
| 87 | + let(:manifest) { 'composite_namevar { php-wibble: ensure=>\'absent\' }' } |
79 | 88 |
|
80 |
| - it { expect(@stdout_str).to match %r{Composite_namevar\[php-wibble\]: Nothing to manage: no ensure and the resource doesn't exist} } |
81 |
| - it { expect(@status.exitstatus).to eq 0 } |
82 |
| - end |
| 89 | + it { expect(@stdout_str).to match %r{Composite_namevar\[php-wibble\]: Nothing to manage: no ensure and the resource doesn't exist} } |
| 90 | + it { expect(@stdout_str).to match %r{Looking for \["php-wibble"\]} } |
| 91 | + it { expect(@status.exitstatus).to eq 0 } |
| 92 | + end |
83 | 93 |
|
84 |
| - context 'when creating a previously absent instance' do |
85 |
| - let(:manifest) { 'composite_namevar { php-wibble: ensure=>\'present\' }' } |
| 94 | + context 'when creating a previously absent instance' do |
| 95 | + let(:manifest) { 'composite_namevar { php-wibble: ensure=>\'present\' }' } |
86 | 96 |
|
87 |
| - it { expect(@stdout_str).to match %r{Composite_namevar\[php-wibble\]/ensure: defined 'ensure' as 'present'} } |
88 |
| - it { expect(@status.exitstatus).to eq 2 } |
89 |
| - end |
| 97 | + it { expect(@stdout_str).to match %r{Composite_namevar\[php-wibble\]/ensure: defined 'ensure' as 'present'} } |
| 98 | + it { expect(@stdout_str).to match %r{Looking for \["php-wibble"\]} } |
| 99 | + it { expect(@status.exitstatus).to eq 2 } |
| 100 | + end |
90 | 101 |
|
91 |
| - context 'when removing a previously present instance' do |
92 |
| - let(:manifest) { 'composite_namevar { php-yum: ensure=>\'absent\' }' } |
| 102 | + context 'when removing a previously present instance' do |
| 103 | + let(:manifest) { 'composite_namevar { php-yum: ensure=>\'absent\' }' } |
93 | 104 |
|
94 |
| - it { expect(@stdout_str).to match %r{Composite_namevar\[php-yum\]/ensure: undefined 'ensure' from 'present'} } |
95 |
| - it { expect(@status.exitstatus).to eq 2 } |
96 |
| - end |
| 105 | + it { expect(@stdout_str).to match %r{Composite_namevar\[php-yum\]/ensure: undefined 'ensure' from 'present'} } |
| 106 | + it { expect(@stdout_str).to match %r{Looking for \["php-yum"\]} } |
| 107 | + it { expect(@status.exitstatus).to eq 2 } |
| 108 | + end |
97 | 109 |
|
98 |
| - context 'when modifying an existing resource through an alternative title_pattern' do |
99 |
| - let(:manifest) { 'composite_namevar { \'php/gem\': value=>\'c\' }' } |
| 110 | + context 'when modifying an existing resource through an alternative title_pattern' do |
| 111 | + let(:manifest) { 'composite_namevar { \'php/gem\': value=>\'c\' }' } |
100 | 112 |
|
101 |
| - it { expect(@stdout_str).to match %r{Current State: \{:title=>"php-gem", :package=>"php", :manager=>"gem", :ensure=>"present", :value=>"b"\}} } |
102 |
| - it { expect(@stdout_str).to match %r{Target State: \{:package=>"php", :manager=>"gem", :value=>"c", :ensure=>"present"\}} } |
103 |
| - it { expect(@status.exitstatus).to eq 2 } |
| 113 | + it { expect(@stdout_str).to match %r{Current State: \{:title=>"php-gem", :package=>"php", :manager=>"gem", :ensure=>"present", :value=>"b"\}} } |
| 114 | + it { expect(@stdout_str).to match %r{Target State: \{:package=>"php", :manager=>"gem", :value=>"c", :ensure=>"present"\}} } |
| 115 | + it { expect(@stdout_str).to match %r{Looking for \["php/gem"\]} } |
| 116 | + it { expect(@status.exitstatus).to eq 2 } |
| 117 | + end |
104 | 118 | end
|
105 | 119 |
|
| 120 | + context 'when using attributes' do |
| 121 | + context 'when managing a present instance' do |
| 122 | + let(:manifest) { 'composite_namevar { "sometitle": package => "php", manager => "gem" }' } |
| 123 | + |
| 124 | + it { expect(@stdout_str).to match %r{Current State: \{:title=>"php-gem", :package=>"php", :manager=>"gem", :ensure=>"present", :value=>"b"\}} } |
| 125 | + it { expect(@stdout_str).to match %r{Looking for \["sometitle"\]} } |
| 126 | + it { expect(@status.exitstatus).to eq 0 } |
| 127 | + end |
| 128 | + |
| 129 | + context 'when managing an absent instance' do |
| 130 | + let(:manifest) { 'composite_namevar { "sometitle": ensure => "absent", package => "php", manager => "wibble" }' } |
| 131 | + |
| 132 | + it { expect(@stdout_str).to match %r{Composite_namevar\[sometitle\]: Nothing to manage: no ensure and the resource doesn't exist} } |
| 133 | + it { expect(@stdout_str).to match %r{Looking for \["sometitle"\]} } |
| 134 | + it { expect(@status.exitstatus).to eq 0 } |
| 135 | + end |
| 136 | + |
| 137 | + context 'when creating a previously absent instance' do |
| 138 | + let(:manifest) { 'composite_namevar { "sometitle": ensure => "present", package => "php", manager => "wibble" }' } |
| 139 | + |
| 140 | + it { expect(@stdout_str).to match %r{Composite_namevar\[sometitle\]/ensure: defined 'ensure' as 'present'} } |
| 141 | + it { expect(@stdout_str).to match %r{Looking for \["sometitle"\]} } |
| 142 | + it { expect(@status.exitstatus).to eq 2 } |
| 143 | + end |
| 144 | + |
| 145 | + context 'when removing a previously present instance' do |
| 146 | + let(:manifest) { 'composite_namevar { "sometitle": ensure => "absent", package => "php", manager => "yum" }' } |
| 147 | + |
| 148 | + it { expect(@stdout_str).to match %r{Composite_namevar\[sometitle\]/ensure: undefined 'ensure' from 'present'} } |
| 149 | + it { expect(@stdout_str).to match %r{Looking for \["sometitle"\]} } |
| 150 | + it { expect(@status.exitstatus).to eq 2 } |
| 151 | + end |
| 152 | + end |
106 | 153 | # rubocop:enable RSpec/InstanceVariable
|
107 | 154 | end
|
108 | 155 | end
|
0 commit comments