diff options
author | Nick Lewis <nick@puppetlabs.com> | 2011-06-08 17:18:22 -0700 |
---|---|---|
committer | Nick Lewis <nick@puppetlabs.com> | 2011-06-08 18:01:31 -0700 |
commit | 376e0f04af01810d00eede4de52744bb8c8e1681 (patch) | |
tree | 4723aa8e5667a664dffa2f3cd10832d9b511b604 /spec/unit/application | |
parent | 4922409a2bdf3ad6a094762c9e2e60371ed16a1b (diff) | |
parent | b1a506c7dec849415073e1bf4b3c92f3c898d6d9 (diff) | |
download | puppet-376e0f04af01810d00eede4de52744bb8c8e1681.tar.gz puppet-376e0f04af01810d00eede4de52744bb8c8e1681.tar.xz puppet-376e0f04af01810d00eede4de52744bb8c8e1681.zip |
Merge branch '2.6.x' into 2.7.x
Conflicts:
acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb
lib/puppet/application/apply.rb
lib/puppet/configurer.rb
lib/puppet/configurer/fact_handler.rb
spec/unit/application/apply_spec.rb
spec/unit/configurer/fact_handler_spec.rb
spec/unit/configurer_spec.rb
Diffstat (limited to 'spec/unit/application')
-rwxr-xr-x | spec/unit/application/agent_spec.rb | 2 | ||||
-rwxr-xr-x | spec/unit/application/apply_spec.rb | 124 | ||||
-rwxr-xr-x | spec/unit/application/facts_spec.rb | 1 |
3 files changed, 72 insertions, 55 deletions
diff --git a/spec/unit/application/agent_spec.rb b/spec/unit/application/agent_spec.rb index c4f8e7176..d87f1f563 100755 --- a/spec/unit/application/agent_spec.rb +++ b/spec/unit/application/agent_spec.rb @@ -545,7 +545,7 @@ describe Puppet::Application::Agent do @host.stubs(:certificate).returns(@cert) @cert.stubs(:fingerprint).with(:MD5).returns("DIGEST") - Puppet.expects(:notice).with("DIGEST") + @puppetd.expects(:puts).with "DIGEST" @puppetd.fingerprint end diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb index 74c883a3e..19a933950 100755 --- a/spec/unit/application/apply_spec.rb +++ b/spec/unit/application/apply_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' require 'puppet/application/apply' require 'puppet/file_bucket/dipper' require 'puppet/configurer' +require 'fileutils' describe Puppet::Application::Apply do before :each do @@ -59,13 +60,12 @@ describe Puppet::Application::Apply do end it "should set show_diff on --noop" do - Puppet.stubs(:[]=) - Puppet.stubs(:[]).with(:config) - Puppet.stubs(:[]).with(:noop).returns(true) - - Puppet.expects(:[]=).with(:show_diff, true) + Puppet[:noop] = true + Puppet[:show_diff] = false @apply.setup + + Puppet[:show_diff].should == true end it "should set console as the log destination if logdest option wasn't provided" do @@ -127,28 +127,29 @@ describe Puppet::Application::Apply do end describe "the main command" do + include PuppetSpec::Files + before :each do - Puppet.stubs(:[]) - Puppet.settings.stubs(:use) - Puppet.stubs(:[]).with(:prerun_command).returns "" - Puppet.stubs(:[]).with(:postrun_command).returns "" - Puppet.stubs(:[]).with(:trace).returns(true) + Puppet[:prerun_command] = '' + Puppet[:postrun_command] = '' - @apply.options.stubs(:[]) + Puppet::Node::Facts.indirection.terminus_class = :memory + Puppet::Node.indirection.terminus_class = :memory - @facts = stub_everything 'facts' - Puppet::Node::Facts.indirection.stubs(:find).returns(@facts) + @facts = Puppet::Node::Facts.new(Puppet[:node_name_value]) + Puppet::Node::Facts.indirection.save(@facts) - @node = stub_everything 'node' - Puppet::Node.indirection.stubs(:find).returns(@node) + @node = Puppet::Node.new(Puppet[:node_name_value]) + Puppet::Node.indirection.save(@node) - @catalog = stub_everything 'catalog' + @catalog = Puppet::Resource::Catalog.new @catalog.stubs(:to_ral).returns(@catalog) + Puppet::Resource::Catalog.indirection.stubs(:find).returns(@catalog) STDIN.stubs(:read) - @transaction = stub_everything 'transaction' + @transaction = Puppet::Transaction.new(@catalog) @catalog.stubs(:apply).returns(@transaction) Puppet::Util::Storage.stubs(:load) @@ -156,7 +157,7 @@ describe Puppet::Application::Apply do end it "should set the code to run from --code" do - @apply.options.stubs(:[]).with(:code).returns("code to run") + @apply.options[:code] = "code to run" Puppet.expects(:[]=).with(:code,"code to run") expect { @apply.main }.to exit_with 0 @@ -172,47 +173,63 @@ describe Puppet::Application::Apply do end it "should set the manifest if a file is passed on command line and the file exists" do - File.stubs(:exist?).with('site.pp').returns true - @apply.command_line.stubs(:args).returns(['site.pp']) + manifest = tmpfile('site.pp') + FileUtils.touch(manifest) + @apply.command_line.stubs(:args).returns([manifest]) - Puppet.expects(:[]=).with(:manifest,"site.pp") + Puppet.expects(:[]=).with(:manifest,manifest) expect { @apply.main }.to exit_with 0 end it "should raise an error if a file is passed on command line and the file does not exist" do - File.stubs(:exist?).with('noexist.pp').returns false - @apply.command_line.stubs(:args).returns(['noexist.pp']) - lambda { @apply.main }.should raise_error(RuntimeError, 'Could not find file noexist.pp') + noexist = tmpfile('noexist.pp') + @apply.command_line.stubs(:args).returns([noexist]) + lambda { @apply.main }.should raise_error(RuntimeError, "Could not find file #{noexist}") end it "should set the manifest to the first file and warn other files will be skipped" do - File.stubs(:exist?).with('starwarsIV').returns true - File.expects(:exist?).with('starwarsI').never - @apply.command_line.stubs(:args).returns(['starwarsIV', 'starwarsI', 'starwarsII']) + manifest = tmpfile('starwarsIV') + FileUtils.touch(manifest) + + @apply.command_line.stubs(:args).returns([manifest, 'starwarsI', 'starwarsII']) - Puppet.expects(:[]=).with(:manifest,"starwarsIV") + Puppet.expects(:[]=).with(:manifest,manifest) Puppet.expects(:warning).with('Only one file can be applied per run. Skipping starwarsI, starwarsII') expect { @apply.main }.to exit_with 0 end - it "should collect the node facts" do - Puppet::Node::Facts.indirection.expects(:find).returns(@facts) + it "should set the facts name based on the node_name_fact" do + @facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name') + Puppet::Node::Facts.indirection.save(@facts) + + node = Puppet::Node.new('other_node_name') + Puppet::Node.indirection.save(node) + + Puppet[:node_name_fact] = 'my_name_fact' expect { @apply.main }.to exit_with 0 + + @facts.name.should == 'other_node_name' end - it "should raise an error if we can't find the node" do - Puppet::Node::Facts.indirection.expects(:find).returns(nil) + it "should set the node_name_value based on the node_name_fact" do + facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name') + Puppet::Node::Facts.indirection.save(facts) + node = Puppet::Node.new('other_node_name') + Puppet::Node.indirection.save(node) + Puppet[:node_name_fact] = 'my_name_fact' - lambda { @apply.main }.should raise_error + expect { @apply.main }.to exit_with 0 + + Puppet[:node_name_value].should == 'other_node_name' end - it "should look for the node" do - Puppet::Node.indirection.expects(:find).returns(@node) + it "should raise an error if we can't find the facts" do + Puppet::Node::Facts.indirection.expects(:find).returns(nil) - expect { @apply.main }.to exit_with 0 + lambda { @apply.main }.should raise_error end it "should raise an error if we can't find the node" do @@ -222,21 +239,20 @@ describe Puppet::Application::Apply do end it "should merge in our node the loaded facts" do - @facts.stubs(:values).returns("values") - - @node.expects(:merge).with("values") + @facts.values = {'key' => 'value'} expect { @apply.main }.to exit_with 0 + + @node.parameters['key'].should == 'value' end it "should load custom classes if loadclasses" do - @apply.options.stubs(:[]).with(:loadclasses).returns(true) - Puppet.stubs(:[]).with(:classfile).returns("/etc/puppet/classes.txt") - FileTest.stubs(:exists?).with("/etc/puppet/classes.txt").returns(true) - FileTest.stubs(:readable?).with("/etc/puppet/classes.txt").returns(true) - File.stubs(:read).with("/etc/puppet/classes.txt").returns("class") + @apply.options[:loadclasses] = true + classfile = tmpfile('classfile') + File.open(classfile, 'w') { |c| c.puts 'class' } + Puppet[:classfile] = classfile - @node.expects(:classes=) + @node.expects(:classes=).with(['class']) expect { @apply.main }.to exit_with 0 end @@ -274,7 +290,7 @@ describe Puppet::Application::Apply do end it "should save the last run summary" do - Puppet.stubs(:[]).with(:noop).returns(false) + Puppet[:noop] = false report = Puppet::Transaction::Report.new("apply") Puppet::Transaction::Report.stubs(:new).returns(report) @@ -283,25 +299,26 @@ describe Puppet::Application::Apply do end describe "with detailed_exitcodes" do + before :each do + @apply.options[:detailed_exitcodes] = true + end + it "should exit with report's computed exit status" do - Puppet.stubs(:[]).with(:noop).returns(false) - @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true) + Puppet[:noop] = false Puppet::Transaction::Report.any_instance.stubs(:exit_status).returns(666) expect { @apply.main }.to exit_with 666 end it "should exit with report's computed exit status, even if --noop is set" do - Puppet.stubs(:[]).with(:noop).returns(true) - @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true) + Puppet[:noop] = true Puppet::Transaction::Report.any_instance.stubs(:exit_status).returns(666) expect { @apply.main }.to exit_with 666 end it "should always exit with 0 if option is disabled" do - Puppet.stubs(:[]).with(:noop).returns(false) - @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(false) + Puppet[:noop] = false report = stub 'report', :exit_status => 666 @transaction.stubs(:report).returns(report) @@ -309,8 +326,7 @@ describe Puppet::Application::Apply do end it "should always exit with 0 if --noop" do - Puppet.stubs(:[]).with(:noop).returns(true) - @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true) + Puppet[:noop] = true report = stub 'report', :exit_status => 666 @transaction.stubs(:report).returns(report) diff --git a/spec/unit/application/facts_spec.rb b/spec/unit/application/facts_spec.rb index e11ea165c..7a7c36597 100755 --- a/spec/unit/application/facts_spec.rb +++ b/spec/unit/application/facts_spec.rb @@ -16,6 +16,7 @@ describe Puppet::Application::Facts do end it "should return facts if a key is given to find", :'fails_on_ruby_1.9.2' => true do + Puppet::Node::Facts.indirection.reset_terminus_class subject.command_line.stubs(:args).returns %w{find whatever --render-as yaml} expect { |