|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib')) |
| 4 | + |
| 5 | +require 'spec_helper_rspec' |
| 6 | +require 'puppet/provider/elastic_parsedfile' |
| 7 | + |
| 8 | +describe Puppet::Provider::ElasticParsedFile do |
| 9 | + subject do |
| 10 | + described_class.tap do |o| |
| 11 | + o.instance_eval { @metadata = :metadata } |
| 12 | + end |
| 13 | + end |
| 14 | + |
| 15 | + it { is_expected.to respond_to :default_target } |
| 16 | + it { is_expected.to respond_to :xpack_config } |
| 17 | + |
| 18 | + context 'when there is no default_target' do |
| 19 | + # describe 'default_target' do |
| 20 | + # it 'returns a single whitespace' do |
| 21 | + # expect(described_class.default_target).to(eq(' ')) |
| 22 | + # end |
| 23 | + # end |
| 24 | + |
| 25 | + describe 'xpack_config' do |
| 26 | + value = 'somefile' |
| 27 | + result = '/etc/elasticsearch/somefile' |
| 28 | + |
| 29 | + it 'fails when no value is given' do |
| 30 | + expect { described_class.xpack_config }.to raise_error(ArgumentError) |
| 31 | + end |
| 32 | + |
| 33 | + it 'defines default_target when given value' do |
| 34 | + expect(described_class.xpack_config(value)).to(eq(result)) |
| 35 | + expect(described_class.instance_variable_get(:@default_target)).to(eq(result)) |
| 36 | + end |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + context 'whene there is a default_target' do |
| 41 | + describe 'xpack_config' do |
| 42 | + default_target = '/etc/elasticsearch/somefile' |
| 43 | + value = 'otherfile' |
| 44 | + described_class.instance_variable_set(:@default_target, default_target) |
| 45 | + |
| 46 | + it 'fails when no value is given' do |
| 47 | + expect { described_class.xpack_config }.to raise_error(ArgumentError) |
| 48 | + end |
| 49 | + |
| 50 | + it 'is idempotent' do |
| 51 | + expect(described_class.xpack_config('somefile')).to(eq(default_target)) |
| 52 | + end |
| 53 | + |
| 54 | + it 'still returns the previously defined target when a new value is given' do |
| 55 | + expect(described_class.xpack_config(value)).to(eq(default_target)) |
| 56 | + end |
| 57 | + end |
| 58 | + end |
| 59 | +end |
0 commit comments