Sha256: fd5670bdb92ef25348c45f572fbcea821d3c5e613def4cf8766ab23abe8fa4e9

Contents?: true

Size: 1.43 KB

Versions: 12

Compression:

Stored size: 1.43 KB

Contents

require 'spec_helper'
require 'hiera/util'

describe "Hiera" do
  context "when doing interpolation" do
    let(:fixtures) { File.join(HieraSpec::FIXTURE_DIR, 'interpolate') }

    it 'should prevent endless recursion' do
      Hiera::Util.expects(:var_dir).at_least_once.returns(File.join(fixtures, 'data'))
      hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera.yaml'))
      expect do
        hiera.lookup('foo', nil, {})
      end.to raise_error Hiera::InterpolationLoop, 'Detected in [hiera("bar"), hiera("foo")]'
    end
  end

  context "when not finding value for interpolated key" do
    let(:fixtures) { File.join(HieraSpec::FIXTURE_DIR, 'interpolate') }

    it 'should resolve the interpolation to an empty string' do
      Hiera::Util.expects(:var_dir).at_least_once.returns(File.join(fixtures, 'data'))
      hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera.yaml'))
      expect(hiera.lookup('niltest', nil, {})).to eq('Missing key ##. Key with nil ##')
    end
  end

  context "when doing interpolation with override" do
    let(:fixtures) { File.join(HieraSpec::FIXTURE_DIR, 'override') }

    it 'should resolve interpolation using the override' do
      Hiera::Util.expects(:var_dir).at_least_once.returns(File.join(fixtures, 'data'))
      hiera = Hiera.new(:config => File.join(fixtures, 'config', 'hiera.yaml'))
      expect(hiera.lookup('foo', nil, {}, 'alternate')).to eq('alternate')
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hiera-3.0.6 spec/unit/interpolate_spec.rb
hiera-3.0.6-x86-mingw32 spec/unit/interpolate_spec.rb
hiera-3.0.6-x64-mingw32 spec/unit/interpolate_spec.rb
hiera-3.0.5 spec/unit/interpolate_spec.rb
hiera-3.0.5-x86-mingw32 spec/unit/interpolate_spec.rb
hiera-3.0.5-x64-mingw32 spec/unit/interpolate_spec.rb
hiera-3.0.1 spec/unit/interpolate_spec.rb
hiera-3.0.1-x86-mingw32 spec/unit/interpolate_spec.rb
hiera-3.0.1-x64-mingw32 spec/unit/interpolate_spec.rb
hiera-2.0.0 spec/unit/interpolate_spec.rb
hiera-2.0.0-x86-mingw32 spec/unit/interpolate_spec.rb
hiera-2.0.0-x64-mingw32 spec/unit/interpolate_spec.rb