diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/functions/ensure_packages_spec.rb | 13 | ||||
-rw-r--r-- | spec/unit/facter/facter_dot_d_spec.rb | 31 | ||||
-rw-r--r-- | spec/unit/facter/pe_required_facts_spec.rb | 70 | ||||
-rw-r--r-- | spec/unit/puppet/parser/functions/concat_spec.rb | 19 |
4 files changed, 60 insertions, 73 deletions
diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb index bf62eff..436be10 100644 --- a/spec/functions/ensure_packages_spec.rb +++ b/spec/functions/ensure_packages_spec.rb @@ -32,7 +32,7 @@ describe 'ensure_packages' do it 'fails with no arguments' do expect { scope.function_ensure_packages([]) - }.to raise_error(Puppet::ParseError, /0 for 1/) + }.to raise_error(Puppet::ParseError, /0 for 1 or 2/) end it 'accepts an array of values' do @@ -67,4 +67,15 @@ describe 'ensure_packages' do expect(catalog.resource(:package, 'facter')['ensure']).to eq('present') end end + + context 'given a clean catalog and specified defaults' do + let :catalog do + compile_to_catalog('ensure_packages(["facter"], {"provider" => "gem"})') + end + + it 'declares package resources with ensure => present' do + expect(catalog.resource(:package, 'facter')['ensure']).to eq('present') + expect(catalog.resource(:package, 'facter')['provider']).to eq('gem') + end + end end diff --git a/spec/unit/facter/facter_dot_d_spec.rb b/spec/unit/facter/facter_dot_d_spec.rb new file mode 100644 index 0000000..1ecffc8 --- /dev/null +++ b/spec/unit/facter/facter_dot_d_spec.rb @@ -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 diff --git a/spec/unit/facter/pe_required_facts_spec.rb b/spec/unit/facter/pe_required_facts_spec.rb deleted file mode 100644 index 85ff6ab..0000000 --- a/spec/unit/facter/pe_required_facts_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -# Puppet Enterprise requires the following facts to be set in order to operate. -# These facts are set using the file ???? and the two facts are -# `fact_stomp_port`, and `fact_stomp_server`. -# - -require 'spec_helper' - -describe "External facts in /etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt" do - context "With Facter 1.6.17 which does not have external facts support" do - before :each do - Facter.stubs(:version).returns("1.6.17") - Facter::Util::Root.stubs(:root?).returns(true) - # Stub out the filesystem for stdlib - Dir.stubs(:entries).with("/etc/puppetlabs/facter/facts.d"). - returns(['puppet_enterprise_installer.txt']) - Dir.stubs(:entries).with("/etc/facter/facts.d").returns([]) - File.stubs(:readlines).with('/etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt'). - returns([ - "fact_stomp_port=61613\n", - "fact_stomp_server=puppetmaster.acme.com\n", - "fact_is_puppetagent=true\n", - "fact_is_puppetmaster=false\n", - "fact_is_puppetca=false\n", - "fact_is_puppetconsole=false\n", - ]) - if Facter.collection.respond_to? :load - Facter.collection.load(:facter_dot_d) - else - Facter.collection.loader.load(:facter_dot_d) - end - end - - it 'defines fact_stomp_port' do - Facter.fact(:fact_stomp_port).value.should == '61613' - end - it 'defines fact_stomp_server' do - Facter.fact(:fact_stomp_server).value.should == 'puppetmaster.acme.com' - end - it 'defines fact_is_puppetagent' do - Facter.fact(:fact_is_puppetagent).value.should == 'true' - end - it 'defines fact_is_puppetmaster' do - Facter.fact(:fact_is_puppetmaster).value.should == 'false' - end - it 'defines fact_is_puppetca' do - Facter.fact(:fact_is_puppetca).value.should == 'false' - end - it 'defines fact_is_puppetconsole' do - Facter.fact(:fact_is_puppetconsole).value.should == 'false' - end - end - - [ '1.7.1', '2.0.1' ].each do |v| - context "With Facter #{v} which has external facts support" do - before :each do - Facter.stubs(:version).returns(v) - end - - it 'does not call Facter::Util::DotD.new' do - Facter::Util::DotD.expects(:new).never - - if Facter.collection.respond_to? :load - Facter.collection.load(:facter_dot_d) - else - Facter.collection.loader.load(:facter_dot_d) - end - end - end - end -end diff --git a/spec/unit/puppet/parser/functions/concat_spec.rb b/spec/unit/puppet/parser/functions/concat_spec.rb index 123188b..6e67620 100644 --- a/spec/unit/puppet/parser/functions/concat_spec.rb +++ b/spec/unit/puppet/parser/functions/concat_spec.rb @@ -4,12 +4,27 @@ require 'spec_helper' describe "the concat function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_concat([]) }.should( raise_error(Puppet::ParseError)) + it "should raise a ParseError if the client does not provide two arguments" do + lambda { scope.function_concat([]) }.should(raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if the first parameter is not an array" do + lambda { scope.function_concat([1, []])}.should(raise_error(Puppet::ParseError)) end it "should be able to concat an array" do result = scope.function_concat([['1','2','3'],['4','5','6']]) result.should(eq(['1','2','3','4','5','6'])) end + + it "should be able to concat a primitive to an array" do + result = scope.function_concat([['1','2','3'],'4']) + result.should(eq(['1','2','3','4'])) + end + + it "should not accidentally flatten nested arrays" do + result = scope.function_concat([['1','2','3'],[['4','5'],'6']]) + result.should(eq(['1','2','3',['4','5'],'6'])) + end + end |