|
40 | 40 | ) |
41 | 41 | provider.create |
42 | 42 | end |
| 43 | + |
| 44 | + it 'warns about unrecognized features' do |
| 45 | + expect(provider).to receive(:request).with(:post, 'api/v2/smart_proxies', {}, kind_of(String)).and_return( |
| 46 | + double(:code => '201', :body => {'features' => [{'name' => 'TFTP'}, {'name' => 'Logs'}], 'unrecognized_features' => ['NewFeature']}.to_json) |
| 47 | + ) |
| 48 | + expect(Puppet).to receive(:warning).with(/Proxy proxy.example.com has features not recognized by Foreman: NewFeature/) |
| 49 | + provider.create |
| 50 | + end |
| 51 | + |
| 52 | + it 'does not warn when there are no unrecognized features' do |
| 53 | + expect(provider).to receive(:request).with(:post, 'api/v2/smart_proxies', {}, kind_of(String)).and_return( |
| 54 | + double(:code => '201', :body => {'features' => [{'name' => 'TFTP'}, {'name' => 'Logs'}], 'unrecognized_features' => []}.to_json) |
| 55 | + ) |
| 56 | + expect(Puppet).not_to receive(:warning) |
| 57 | + provider.create |
| 58 | + end |
43 | 59 | end |
44 | 60 |
|
45 | 61 | describe '#destroy' do |
|
128 | 144 | ) |
129 | 145 | provider.refresh_features! |
130 | 146 | end |
| 147 | + |
| 148 | + it 'warns about unrecognized features instead of validating' do |
| 149 | + expect(provider).to receive(:id).and_return(1) |
| 150 | + expect(provider).to receive(:request).with(:put, 'api/v2/smart_proxies/1/refresh').and_return( |
| 151 | + double(:code => '200', :body => {'features' => [{'name' => 'TFTP'}], 'unrecognized_features' => ['NewFeature']}.to_json) |
| 152 | + ) |
| 153 | + expect(Puppet).to receive(:warning).with(/Proxy proxy.example.com has features not recognized by Foreman: NewFeature/) |
| 154 | + provider.refresh_features! |
| 155 | + end |
| 156 | + |
| 157 | + it 'does not warn when unrecognized features list is empty' do |
| 158 | + expect(provider).to receive(:id).and_return(1) |
| 159 | + expect(provider).to receive(:request).with(:put, 'api/v2/smart_proxies/1/refresh').and_return( |
| 160 | + double(:code => '200', :body => {'features' => [{'name' => 'TFTP'}, {'name' => 'Logs'}], 'unrecognized_features' => []}.to_json) |
| 161 | + ) |
| 162 | + expect(Puppet).not_to receive(:warning) |
| 163 | + provider.refresh_features! |
| 164 | + end |
| 165 | + |
| 166 | + it 'skips feature validation when unrecognized features are present' do |
| 167 | + expect(provider).to receive(:id).and_return(1) |
| 168 | + expect(provider).to receive(:request).with(:put, 'api/v2/smart_proxies/1/refresh').and_return( |
| 169 | + double(:code => '200', :body => {'features' => [{'name' => 'TFTP'}], 'unrecognized_features' => ['Logs']}.to_json) |
| 170 | + ) |
| 171 | + expect(Puppet).to receive(:warning).with(/Logs/) |
| 172 | + expect { provider.refresh_features! }.not_to raise_error |
| 173 | + end |
131 | 174 | end |
132 | 175 |
|
133 | 176 | context 'without features in refresh response re-fetches proxy' do |
|
152 | 195 | ) |
153 | 196 | expect { provider.refresh_features! }.to raise_error(Puppet::Error, /Proxy proxy.example.com has failed to load one or more features \(Logs\)/) |
154 | 197 | end |
| 198 | + |
| 199 | + it 'warns about unrecognized features after re-fetch' do |
| 200 | + expect(provider).to receive(:id).and_return(1) |
| 201 | + expect(provider).to receive(:request).with(:put, 'api/v2/smart_proxies/1/refresh').and_return( |
| 202 | + double(:code => '200', :body => {}.to_json) |
| 203 | + ) |
| 204 | + expect(provider).to receive(:request).with(:get, 'api/v2/smart_proxies', :search => 'name="proxy.example.com"').and_return( |
| 205 | + double('response', :body => {:results => [{:id => 1, :name => 'proxy.example.com', 'features' => [{'name' => 'TFTP'}], 'unrecognized_features' => ['Logs']}]}.to_json, :code => '200') |
| 206 | + ) |
| 207 | + expect(Puppet).to receive(:warning).with(/Proxy proxy.example.com has features not recognized by Foreman: Logs/) |
| 208 | + expect { provider.refresh_features! }.not_to raise_error |
| 209 | + end |
155 | 210 | end |
156 | 211 | end |
157 | 212 |
|
|
0 commit comments