diff options
| author | Jesse Wolfe <jes5199@gmail.com> | 2010-04-13 14:53:44 -0700 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | 1d8bd0d9308413b2f0772a65ee76d69d8fa5959b (patch) | |
| tree | 66117b98ff550ee0352fe3d599b98137044691da /spec/unit/application | |
| parent | 722a27fd49fc2c5ac16123e9e34967db025178f5 (diff) | |
| download | puppet-1d8bd0d9308413b2f0772a65ee76d69d8fa5959b.tar.gz puppet-1d8bd0d9308413b2f0772a65ee76d69d8fa5959b.tar.xz puppet-1d8bd0d9308413b2f0772a65ee76d69d8fa5959b.zip | |
Fix #3552 single executable should display usage
Added some tests to make the single executable command behavior
explicit.
Added logic to display the usage message if we're on a tty and no
arguments are passed.
Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
Diffstat (limited to 'spec/unit/application')
| -rwxr-xr-x | spec/unit/application/apply.rb (renamed from spec/unit/application/main.rb) | 151 |
1 files changed, 76 insertions, 75 deletions
diff --git a/spec/unit/application/main.rb b/spec/unit/application/apply.rb index ea8c43fe6..e9a1c72a0 100755 --- a/spec/unit/application/main.rb +++ b/spec/unit/application/apply.rb @@ -2,33 +2,33 @@ require File.dirname(__FILE__) + '/../../spec_helper' -require 'puppet/application/main' +require 'puppet/application/apply' describe "Puppet" do before :each do - @main = Puppet::Application[:main] + @apply = Puppet::Application[:apply] Puppet::Util::Log.stubs(:newdestination) Puppet::Util::Log.stubs(:level=) end [:debug,:loadclasses,:verbose,:use_nodes,:detailed_exitcodes].each do |option| it "should declare handle_#{option} method" do - @main.should respond_to("handle_#{option}".to_sym) + @apply.should respond_to("handle_#{option}".to_sym) end it "should store argument value when calling handle_#{option}" do - @main.options.expects(:[]=).with(option, 'arg') - @main.send("handle_#{option}".to_sym, 'arg') + @apply.options.expects(:[]=).with(option, 'arg') + @apply.send("handle_#{option}".to_sym, 'arg') end end it "should set the code to the provided code when :execute is used" do - @main.options.expects(:[]=).with(:code, 'arg') - @main.send("handle_execute".to_sym, 'arg') + @apply.options.expects(:[]=).with(:code, 'arg') + @apply.send("handle_execute".to_sym, 'arg') end it "should ask Puppet::Application to parse Puppet configuration file" do - @main.should_parse_config?.should be_true + @apply.should_parse_config?.should be_true end describe "when applying options" do @@ -36,13 +36,13 @@ describe "Puppet" do it "should set the log destination with --logdest" do Puppet::Log.expects(:newdestination).with("console") - @main.handle_logdest("console") + @apply.handle_logdest("console") end it "should put the logset options to true" do - @main.options.expects(:[]=).with(:logset,true) + @apply.options.expects(:[]=).with(:logset,true) - @main.handle_logdest("console") + @apply.handle_logdest("console") end end @@ -53,10 +53,11 @@ describe "Puppet" do Puppet.stubs(:trap) Puppet::Log.stubs(:level=) Puppet.stubs(:parse_config) + require 'lib/puppet/file_bucket/dipper' Puppet::FileBucket::Dipper.stubs(:new) STDIN.stubs(:read) - @main.options.stubs(:[]).with(any_parameters) + @apply.options.stubs(:[]).with(any_parameters) end it "should set show_diff on --noop" do @@ -66,50 +67,50 @@ describe "Puppet" do Puppet.expects(:[]=).with(:show_diff, true) - @main.run_setup + @apply.run_setup end it "should set console as the log destination if logdest option wasn't provided" do Puppet::Log.expects(:newdestination).with(:console) - @main.run_setup + @apply.run_setup end it "should set INT trap" do - @main.expects(:trap).with(:INT) + @apply.expects(:trap).with(:INT) - @main.run_setup + @apply.run_setup end it "should set log level to debug if --debug was passed" do - @main.options.stubs(:[]).with(:debug).returns(true) + @apply.options.stubs(:[]).with(:debug).returns(true) Puppet::Log.expects(:level=).with(:debug) - @main.run_setup + @apply.run_setup end it "should set log level to info if --verbose was passed" do - @main.options.stubs(:[]).with(:verbose).returns(true) + @apply.options.stubs(:[]).with(:verbose).returns(true) Puppet::Log.expects(:level=).with(:info) - @main.run_setup + @apply.run_setup end it "should print puppet config if asked to in Puppet config" do - @main.stubs(:exit) + @apply.stubs(:exit) Puppet.settings.stubs(:print_configs?).returns(true) Puppet.settings.expects(:print_configs) - @main.run_setup + @apply.run_setup end it "should exit after printing puppet config if asked to in Puppet config" do Puppet.settings.stubs(:print_configs?).returns(true) - lambda { @main.run_setup }.should raise_error(SystemExit) + lambda { @apply.run_setup }.should raise_error(SystemExit) end end @@ -117,23 +118,23 @@ describe "Puppet" do describe "when executing" do it "should dispatch to parseonly if parseonly is set" do - @main.stubs(:options).returns({}) + @apply.stubs(:options).returns({}) Puppet.stubs(:[]).with(:parseonly).returns(true) - @main.get_command.should == :parseonly + @apply.get_command.should == :parseonly end it "should dispatch to 'apply' if it was called with 'apply'" do - @main.options[:catalog] = "foo" + @apply.options[:catalog] = "foo" - @main.get_command.should == :apply + @apply.get_command.should == :apply end it "should dispatch to main if parseonly is not set" do - @main.stubs(:options).returns({}) + @apply.stubs(:options).returns({}) Puppet.stubs(:[]).with(:parseonly).returns(false) - @main.get_command.should == :main + @apply.get_command.should == :main end describe "the parseonly command" do @@ -141,26 +142,26 @@ describe "Puppet" do Puppet.stubs(:[]).with(:environment) Puppet.stubs(:[]).with(:manifest).returns("site.pp") Puppet.stubs(:err) - @main.stubs(:exit) - @main.options.stubs(:[]).with(:code).returns "some code" + @apply.stubs(:exit) + @apply.options.stubs(:[]).with(:code).returns "some code" @collection = stub_everything Puppet::Resource::TypeCollection.stubs(:new).returns(@collection) end it "should use a Puppet Resource Type Collection to parse the file" do @collection.expects(:perform_initial_import) - @main.parseonly + @apply.parseonly end it "should exit with exit code 0 if no error" do - @main.expects(:exit).with(0) - @main.parseonly + @apply.expects(:exit).with(0) + @apply.parseonly end it "should exit with exit code 1 if error" do @collection.stubs(:perform_initial_import).raises(Puppet::ParseError) - @main.expects(:exit).with(1) - @main.parseonly + @apply.expects(:exit).with(1) + @apply.parseonly end end @@ -172,7 +173,7 @@ describe "Puppet" do Puppet.stubs(:[]).with(:postrun_command).returns "" Puppet.stubs(:[]).with(:trace).returns(true) - @main.options.stubs(:[]) + @apply.options.stubs(:[]) @facts = stub_everything 'facts' Puppet::Node::Facts.stubs(:find).returns(@facts) @@ -189,14 +190,14 @@ describe "Puppet" do @transaction = stub_everything 'transaction' @catalog.stubs(:apply).returns(@transaction) - @main.stubs(:exit) + @apply.stubs(:exit) end it "should set the code to run from --code" do - @main.options.stubs(:[]).with(:code).returns("code to run") + @apply.options.stubs(:[]).with(:code).returns("code to run") Puppet.expects(:[]=).with(:code,"code to run") - @main.main + @apply.main end it "should set the code to run from STDIN if no arguments" do @@ -205,7 +206,7 @@ describe "Puppet" do Puppet.expects(:[]=).with(:code,"code to run") - @main.main + @apply.main end it "should set the manifest if some files are passed on command line" do @@ -214,31 +215,31 @@ describe "Puppet" do Puppet.expects(:[]=).with(:manifest,"site.pp") - @main.main + @apply.main end it "should collect the node facts" do Puppet::Node::Facts.expects(:find).returns(@facts) - @main.main + @apply.main end it "should raise an error if we can't find the node" do Puppet::Node::Facts.expects(:find).returns(nil) - lambda { @main.main }.should raise_error + lambda { @apply.main }.should raise_error end it "should find the node" do Puppet::Node.expects(:find).returns(@node) - @main.main + @apply.main end it "should raise an error if we can't find the node" do Puppet::Node.expects(:find).returns(nil) - lambda { @main.main }.should raise_error + lambda { @apply.main }.should raise_error end it "should merge in our node the loaded facts" do @@ -246,11 +247,11 @@ describe "Puppet" do @node.expects(:merge).with("values") - @main.main + @apply.main end it "should load custom classes if loadclasses" do - @main.options.stubs(:[]).with(:loadclasses).returns(true) + @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) @@ -258,26 +259,26 @@ describe "Puppet" do @node.expects(:classes=) - @main.main + @apply.main end it "should compile the catalog" do Puppet::Resource::Catalog.expects(:find).returns(@catalog) - @main.main + @apply.main end it "should transform the catalog to ral" do @catalog.expects(:to_ral).returns(@catalog) - @main.main + @apply.main end it "should finalize the catalog" do @catalog.expects(:finalize) - @main.main + @apply.main end it "should call the prerun and postrun commands on a Configurer instance" do @@ -287,87 +288,87 @@ describe "Puppet" do configurer.expects(:execute_prerun_command) configurer.expects(:execute_postrun_command) - @main.main + @apply.main end it "should apply the catalog" do @catalog.expects(:apply) - @main.main + @apply.main end describe "with detailed_exitcodes" do it "should exit with report's computed exit status" do Puppet.stubs(:[]).with(:noop).returns(false) - @main.options.stubs(:[]).with(:detailed_exitcodes).returns(true) + @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true) report = stub 'report', :exit_status => 666 @transaction.stubs(:report).returns(report) - @main.expects(:exit).with(666) + @apply.expects(:exit).with(666) - @main.main + @apply.main end it "should always exit with 0 if option is disabled" do Puppet.stubs(:[]).with(:noop).returns(false) - @main.options.stubs(:[]).with(:detailed_exitcodes).returns(false) + @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(false) report = stub 'report', :exit_status => 666 @transaction.stubs(:report).returns(report) - @main.expects(:exit).with(0) + @apply.expects(:exit).with(0) - @main.main + @apply.main end it "should always exit with 0 if --noop" do Puppet.stubs(:[]).with(:noop).returns(true) - @main.options.stubs(:[]).with(:detailed_exitcodes).returns(true) + @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true) report = stub 'report', :exit_status => 666 @transaction.stubs(:report).returns(report) - @main.expects(:exit).with(0) + @apply.expects(:exit).with(0) - @main.main + @apply.main end end end describe "the 'apply' command" do it "should read the catalog in from disk if a file name is provided" do - @main.options[:catalog] = "/my/catalog.pson" + @apply.options[:catalog] = "/my/catalog.pson" File.expects(:read).with("/my/catalog.pson").returns "something" Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,'something').returns Puppet::Resource::Catalog.new - @main.apply + @apply.apply end it "should read the catalog in from stdin if '-' is provided" do - @main.options[:catalog] = "-" + @apply.options[:catalog] = "-" $stdin.expects(:read).returns "something" Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,'something').returns Puppet::Resource::Catalog.new - @main.apply + @apply.apply end it "should deserialize the catalog from the default format" do - @main.options[:catalog] = "/my/catalog.pson" + @apply.options[:catalog] = "/my/catalog.pson" File.stubs(:read).with("/my/catalog.pson").returns "something" Puppet::Resource::Catalog.stubs(:default_format).returns :rot13_piglatin Puppet::Resource::Catalog.stubs(:convert_from).with(:rot13_piglatin,'something').returns Puppet::Resource::Catalog.new - @main.apply + @apply.apply end it "should fail helpfully if deserializing fails" do - @main.options[:catalog] = "/my/catalog.pson" + @apply.options[:catalog] = "/my/catalog.pson" File.stubs(:read).with("/my/catalog.pson").returns "something syntacically invalid" - lambda { @main.apply }.should raise_error(Puppet::Error) + lambda { @apply.apply }.should raise_error(Puppet::Error) end it "should convert plain data structures into a catalog if deserialization does not do so" do - @main.options[:catalog] = "/my/catalog.pson" + @apply.options[:catalog] = "/my/catalog.pson" File.stubs(:read).with("/my/catalog.pson").returns "something" Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,"something").returns({:foo => "bar"}) Puppet::Resource::Catalog.expects(:pson_create).with({:foo => "bar"}).returns(Puppet::Resource::Catalog.new) - @main.apply + @apply.apply end it "should convert the catalog to a RAL catalog and use a Configurer instance to apply it" do - @main.options[:catalog] = "/my/catalog.pson" + @apply.options[:catalog] = "/my/catalog.pson" File.stubs(:read).with("/my/catalog.pson").returns "something" catalog = Puppet::Resource::Catalog.new Puppet::Resource::Catalog.stubs(:convert_from).with(:pson,'something').returns catalog @@ -377,7 +378,7 @@ describe "Puppet" do Puppet::Configurer.expects(:new).returns configurer configurer.expects(:run).with(:catalog => "mycatalog") - @main.apply + @apply.apply end end end |
