|
16 | 16 | end |
17 | 17 |
|
18 | 18 | it_should_behave_like "Hiera indirection", Puppet::DataBinding::Hiera, my_fixture_dir |
| 19 | + |
| 20 | + describe "#find", :if => Puppet.features.hiera? do |
| 21 | + let(:data_binder) { described_class.new } |
| 22 | + let(:hiera) { double('hiera') } |
| 23 | + |
| 24 | + def request(key, options = {}) |
| 25 | + Puppet::Indirector::Request.new(:hiera, :find, key, nil, options) |
| 26 | + end |
| 27 | + |
| 28 | + before do |
| 29 | + allow(described_class).to receive(:hiera).and_return(hiera) |
| 30 | + end |
| 31 | + |
| 32 | + it "throws :no_such_key when hiera returns the not_found sentinel" do |
| 33 | + # Returning the default argument signals "not found" to the find method |
| 34 | + allow(hiera).to receive(:lookup) { |_key, default, *_| default } |
| 35 | + expect { data_binder.find(request('missing')) }.to throw_symbol(:no_such_key) |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + describe "#convert_merge", :if => Puppet.features.hiera? do |
| 40 | + let(:data_binder) { described_class.new } |
| 41 | + |
| 42 | + def convert(merge) |
| 43 | + data_binder.send(:convert_merge, merge) |
| 44 | + end |
| 45 | + |
| 46 | + it "returns nil for nil" do |
| 47 | + expect(convert(nil)).to be_nil |
| 48 | + end |
| 49 | + |
| 50 | + it "returns nil for 'first'" do |
| 51 | + expect(convert('first')).to be_nil |
| 52 | + end |
| 53 | + |
| 54 | + it "returns :array for 'unique'" do |
| 55 | + expect(convert('unique')).to eq(:array) |
| 56 | + end |
| 57 | + |
| 58 | + it "returns native hash behavior for 'hash'" do |
| 59 | + expect(convert('hash')).to eq({ :behavior => :native }) |
| 60 | + end |
| 61 | + |
| 62 | + it "returns deeper hash behavior for 'deep'" do |
| 63 | + expect(convert('deep')).to eq({ :behavior => :deeper }) |
| 64 | + end |
| 65 | + |
| 66 | + it "delegates to the strategy's configuration when given a MergeStrategy" do |
| 67 | + strategy = instance_double(Puppet::Pops::MergeStrategy, :configuration => 'unique') |
| 68 | + expect(convert(strategy)).to eq(:array) |
| 69 | + end |
| 70 | + |
| 71 | + it "returns deeper hash behavior for a Hash with strategy 'deep'" do |
| 72 | + expect(convert({ 'strategy' => 'deep' })).to eq({ :behavior => :deeper }) |
| 73 | + end |
| 74 | + |
| 75 | + it "forwards extra keys alongside deeper behavior for a Hash with strategy 'deep'" do |
| 76 | + result = convert({ 'strategy' => 'deep', 'knockout_prefix' => '--' }) |
| 77 | + expect(result).to eq({ :behavior => :deeper, :knockout_prefix => '--' }) |
| 78 | + end |
| 79 | + |
| 80 | + it "delegates to the string strategy for a Hash with a non-deep strategy" do |
| 81 | + expect(convert({ 'strategy' => 'unique' })).to eq(:array) |
| 82 | + end |
| 83 | + |
| 84 | + it "raises LookupError for an unrecognized merge value" do |
| 85 | + expect { convert('bogus') }.to raise_error(Puppet::DataBinding::LookupError, /Unrecognized value.*bogus/) |
| 86 | + end |
| 87 | + end |
19 | 88 | end |
0 commit comments