Skip to content

Commit

Permalink
Merge pull request redhat-openstack#242 from apenney/facts_d
Browse files Browse the repository at this point in the history
Adjust the regular expression for facts.
  • Loading branch information
hunner committed Apr 22, 2014
2 parents 6a5dee2 + 68acb59 commit 1bdb213
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/facter/facter_dot_d.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def fact_type(file)

def txt_parser(file)
File.readlines(file).each do |line|
if line =~ /^(.+)=(.+)$/
if line =~ /^([^=]+)=(.+)$/
var = $1; val = $2

Facter.add(var) do
Expand Down
31 changes: 31 additions & 0 deletions spec/unit/facter/facter_dot_d_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'spec_helper'
require 'facter/facter_dot_d'

describe Facter::Util::DotD do

context 'returns a simple fact' do
before :each do
Facter.stubs(:version).returns('1.6.1')
subject.stubs(:entries).returns(['/etc/facter/facts.d/fake_fact.txt'])
File.stubs(:readlines).with('/etc/facter/facts.d/fake_fact.txt').returns(['fake_fact=fake fact'])
subject.create
end

it 'should return successfully' do
Facter.fact(:fake_fact).value.should == 'fake fact'
end
end

context 'returns a fact with equals signs' do
before :each do
Facter.stubs(:version).returns('1.6.1')
subject.stubs(:entries).returns(['/etc/facter/facts.d/foo.txt'])
File.stubs(:readlines).with('/etc/facter/facts.d/foo.txt').returns(['foo=1+1=2'])
subject.create
end

it 'should return successfully' do
Facter.fact(:foo).value.should == '1+1=2'
end
end
end

0 comments on commit 1bdb213

Please sign in to comment.