|
4 | 4 | provider_class = Puppet::Type.type(:postgresql_conf).provider(:ruby)
|
5 | 5 |
|
6 | 6 | describe provider_class do
|
7 |
| - let(:resource) { Puppet::Type.type(:postgresql_conf).new(name: 'foo', value: 'bar') } |
| 7 | + let(:resource) { Puppet::Type.type(:postgresql_conf).new(name: 'foo', key: 'foo', value: 'bar') } |
8 | 8 | let(:provider) { resource.provider }
|
9 | 9 |
|
10 | 10 | before(:each) do
|
11 | 11 | allow(provider).to receive(:file_path).and_return('/tmp/foo')
|
12 | 12 | allow(provider).to receive(:read_file).and_return('foo = bar')
|
13 | 13 | allow(provider).to receive(:write_file).and_return(true)
|
| 14 | + allow(provider).to receive(:resource).and_return(key: 'your_key', line_number: 1, value: 'foo') |
14 | 15 | end
|
15 | 16 | # rubocop:enable RSpec/ReceiveMessages
|
16 | 17 |
|
|
26 | 27 | expect(provider).to respond_to(:add_header)
|
27 | 28 | end
|
28 | 29 |
|
29 |
| - it 'has a method exists?' do |
30 |
| - expect(provider).to respond_to(:exists?) |
| 30 | + describe '#exists?' do |
| 31 | + it 'returns true when a matching config item is found' do |
| 32 | + config_data = [{ key: 'your_key', value: 'your_value' }] |
| 33 | + expect(provider).to receive(:parse_config).and_return(config_data) |
| 34 | + |
| 35 | + expect(provider.exists?).to be true |
| 36 | + end |
| 37 | + |
| 38 | + it 'returns false when no matching config item is found' do |
| 39 | + config_data = [{ key: 'other_key', value: 'other_value' }] |
| 40 | + expect(provider).to receive(:parse_config).and_return(config_data) |
| 41 | + |
| 42 | + expect(provider.exists?).to be false |
| 43 | + end |
| 44 | + |
| 45 | + it 'raises an error when multiple matching config items are found' do |
| 46 | + config_data = [{ key: 'your_key', value: 'value1' }, { key: 'your_key', value: 'value2' }] |
| 47 | + expect(provider).to receive(:parse_config).and_return(config_data) |
| 48 | + |
| 49 | + expect { provider.exists? }.to raise_error(Puppet::Error, 'found multiple config items of your_key, please fix this') |
| 50 | + end |
31 | 51 | end
|
32 | 52 |
|
33 | 53 | it 'has a method create' do
|
|
0 commit comments