Skip to content

Commit

Permalink
validate fact to be added in refresh_fact not in inside method
Browse files Browse the repository at this point in the history
  • Loading branch information
Kozakowski Karol committed Mar 16, 2016
1 parent da402ee commit 1ba4bfa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 34 deletions.
17 changes: 3 additions & 14 deletions lib/puppet_x/coi/jboss/factsrefresher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,28 @@ class << self
def refresh_facts value
facts = Facter.list # get list of symbols of facts in the system
value.each do |val|
if validate_fact_name(val.to_s)
self.delete_resolves val
self.delete_value val
raise Puppet::Error, 'You can only delete fact that are made by jboss_module(start with jboss_)' unless validate_fact_name val
delete_resolves val
delete_value val

config = Puppet_X::Coi::Jboss::Configuration::read
fact_value = config[val.to_sym]
Puppet_X::Coi::Jboss::Facts::add_fact(val.to_sym, fact_value)
else
raise Puppet::Error, 'Argument error, given symbol: %s is on valid fact' % val
end
end
end

# Method used to delete resolves in given fact
# @param {String} fact name that resolves should be deleted
def delete_resolves value
if validate_fact_name value
fct = Facter.fact value
fct.instance_variable_set(:@resolves, [])
else
raise Puppet::Error, 'You can only delete fact that are made by jboss_module(start with jboss_)'
end
end

# Method used to delete values in given fact
# @param {String} fact name that value should be deleted
def delete_value value
if validate_fact_name value
fct = Facter.fact value
fct.instance_variable_set(:@value, {})
else
raise Puppet::Error, 'You can only delete fact that are made by jboss_module(start with jboss_)'
end
end

private
Expand Down
20 changes: 0 additions & 20 deletions spec/unit/facter/facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
let(:fact) { 'jboss_fact' }
it { expect(subject).to eq([]) }
end

context '#delete system fact' do

let(:fact) { 'test_fact' }
it { expect { subject }.to raise_error(Puppet::Error, 'You can only delete fact that are made by jboss_module(start with jboss_)') }
end
end

describe '#delete value' do
Expand All @@ -48,12 +42,6 @@
let(:fact) { 'jboss_fact' }
it { expect(subject).to eq({}) }
end

context '#delete_value of system fact' do
let(:fact) { 'test_fact' }

it { expect { subject }.to raise_error(Puppet::Error, 'You can only delete fact that are made by jboss_module(start with jboss_)') }
end
end
end

Expand All @@ -69,14 +57,6 @@
let(:facts) { ['jboss_test_fact'] }
it { expect(subject).to eq(["jboss_test_fact"]) }
end

context 'raise error if fact is not real' do
before :each do
expect(Facter).to receive(:list).and_return(['test_fact', 'jboss_test_fact'])
end
let(:facts) { ['asd'] }
it { expect{subject}.to raise_error(Puppet::Error, 'Argument error, given symbol: asd is on valid fact') }
end
end
end
end

0 comments on commit 1ba4bfa

Please sign in to comment.