Skip to content

Commit 80282a5

Browse files
authored
Merge pull request #1150 from b1-systems/master
Define default_target for parsed file providers
2 parents c9a8522 + 4bc8a4e commit 80282a5

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

lib/puppet/provider/elastic_parsedfile.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ class Puppet::Provider::ElasticParsedFile < Puppet::Provider::ParsedFile
99
#
1010
# @return String
1111
def self.xpack_config(val)
12-
@xpack_config ||= "/etc/elasticsearch/#{val}"
12+
self.default_target ||= "/etc/elasticsearch/#{val}"
1313
end
1414
end
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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

Comments
 (0)