Skip to content

Commit

Permalink
(MODULES-3951) Add unit test for stringify_facts fact
Browse files Browse the repository at this point in the history
Previously there were no tests for the stringify_facts fact.  This commit
adds unit tests for this fact by mocking the Puppet.settings values.  This
commit also adds a test to ensure that catalog compilation fails if
stringify_facts evaluates as true.
  • Loading branch information
glennsarti committed Oct 10, 2016
1 parent 1687132 commit 251e8ef
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/classes/puppet_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,21 @@ def global_facts(facts, os)
it { is_expected.to raise_error(Puppet::Error, /Nexenta not supported/) }
end
end

context 'stringify_facts is set to true' do
describe 'when puppet_stringify_facts evaluates as true ' do
# Mock a supported agent but with puppet_stringify_facts set to true
let(:facts) {{
:osfamily => 'windows',
:operatingsystem => '',
:puppet_ssldir => '/dev/null/ssl',
:puppet_config => '/dev/null/puppet.conf',
:architecture => 'i386',
:puppet_stringify_facts => true,
}}
let(:params) { global_params }

it { is_expected.to raise_error(Puppet::Error, /requires stringify_facts to be disabled/) }
end
end
end
42 changes: 42 additions & 0 deletions spec/unit/facter/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,48 @@
end
end

describe "puppet_stringify_facts fact for Puppet 4.x+", :unless => /3\./ =~ Puppet.version do
subject { Facter.fact("puppet_stringify_facts".to_sym).value }
after(:each) { Facter.clear }

describe 'should always be false' do
it { is_expected.to eq(false) }
end
end

describe "puppet_stringify_facts fact for Puppet 3.x", :if => /3\./ =~ Puppet.version do
subject { Facter.fact("puppet_stringify_facts".to_sym).value }
after(:each) { Facter.clear }

describe 'when not set in Puppet' do
before(:each) {
mocked_settings = Puppet::Settings.new
Puppet.stubs(:settings).returns(mocked_settings)
}
it { is_expected.to eq(false) }
end

describe 'when set false in Puppet' do
before(:each) {
mocked_settings = Puppet::Settings.new
mocked_settings.define_settings :main, :stringify_facts => { :default => false, :type => :boolean, :desc => 'mocked stringify_facts setting' }
Puppet.stubs(:settings).returns(mocked_settings)
}

it { is_expected.to eq(false) }
end

describe 'when set true in Puppet' do
before(:each) {
mocked_settings = Puppet::Settings.new
mocked_settings.define_settings :main, :stringify_facts => { :default => true, :type => :boolean, :desc => 'mocked stringify_facts setting' }
Puppet.stubs(:settings).returns(mocked_settings)
}

it { is_expected.to eq(true) }
end
end

describe "puppet_sslpaths fact" do
subject { Facter.fact("puppet_sslpaths".to_sym).value }
after(:each) { Facter.clear }
Expand Down

0 comments on commit 251e8ef

Please sign in to comment.