|
30 | 30 | end |
31 | 31 | end |
32 | 32 |
|
| 33 | + context 'PuppetDB API compatibility layer' do |
| 34 | + before(:each) do |
| 35 | + clazz = double('OctocatalogDiff::PuppetDB') |
| 36 | + allow(clazz).to receive(:get) { |args| [{ 'certname' => 'foo.bar.com', 'name' => 'uri', 'value' => args }] } |
| 37 | + allow(OctocatalogDiff::PuppetDB).to receive(:new).and_return(clazz) |
| 38 | + end |
| 39 | + |
| 40 | + it 'should use the correct URL for API v3' do |
| 41 | + opts = { |
| 42 | + puppetdb_api_version: 3, |
| 43 | + puppetdb_url: 'https://foo.bar.baz:8081' |
| 44 | + } |
| 45 | + result = OctocatalogDiff::Facts::PuppetDB.fact_retriever(opts, 'foo.bar.com') |
| 46 | + expect(result).to eq('name' => 'foo.bar.com', 'values' => { 'uri' => '/v3/nodes/foo.bar.com/facts' }) |
| 47 | + end |
| 48 | + |
| 49 | + it 'should use the correct URL for API v4' do |
| 50 | + opts = { |
| 51 | + puppetdb_api_version: 4, |
| 52 | + puppetdb_url: 'https://foo.bar.baz:8081' |
| 53 | + } |
| 54 | + result = OctocatalogDiff::Facts::PuppetDB.fact_retriever(opts, 'foo.bar.com') |
| 55 | + expect(result).to eq('name' => 'foo.bar.com', 'values' => { 'uri' => '/pdb/query/v4/nodes/foo.bar.com/facts' }) |
| 56 | + end |
| 57 | + |
| 58 | + it 'should default to API v4' do |
| 59 | + opts = { |
| 60 | + puppetdb_url: 'https://foo.bar.baz:8081' |
| 61 | + } |
| 62 | + result = OctocatalogDiff::Facts::PuppetDB.fact_retriever(opts, 'foo.bar.com') |
| 63 | + expect(result).to eq('name' => 'foo.bar.com', 'values' => { 'uri' => '/pdb/query/v4/nodes/foo.bar.com/facts' }) |
| 64 | + end |
| 65 | + |
| 66 | + it 'should fail if an unrecognized API version is provided' do |
| 67 | + opts = { |
| 68 | + puppetdb_api_version: 9000, |
| 69 | + puppetdb_url: 'https://foo.bar.baz:8081' |
| 70 | + } |
| 71 | + expect { OctocatalogDiff::Facts::PuppetDB.fact_retriever(opts, 'foo.bar.com') }.to raise_error(KeyError) |
| 72 | + end |
| 73 | + end |
| 74 | + |
33 | 75 | context 'mocking methods for error testing' do |
34 | 76 | describe '#fact_retriever' do |
35 | 77 | let(:opts) { { puppetdb_url: 'https://mocked-puppetdb.somedomain.xyz:8081', node: 'valid-facts' } } |
|
0 commit comments