summaryrefslogtreecommitdiffstats
path: root/spec/unit/application/kick_spec.rb
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
commit3180b9d9b2c844dade1d361326600f7001ec66dd (patch)
tree98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /spec/unit/application/kick_spec.rb
parent543225970225de5697734bfaf0a6eee996802c04 (diff)
downloadpuppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
Diffstat (limited to 'spec/unit/application/kick_spec.rb')
-rwxr-xr-xspec/unit/application/kick_spec.rb454
1 files changed, 227 insertions, 227 deletions
diff --git a/spec/unit/application/kick_spec.rb b/spec/unit/application/kick_spec.rb
index 0a530b4b8..dea7ec147 100755
--- a/spec/unit/application/kick_spec.rb
+++ b/spec/unit/application/kick_spec.rb
@@ -6,308 +6,308 @@ require 'puppet/application/kick'
describe Puppet::Application::Kick do
- confine "Kick's eventloops can only start on POSIX" => Puppet.features.posix?
-
- before :each do
- require 'puppet/util/ldap/connection'
- Puppet::Util::Ldap::Connection.stubs(:new).returns(stub_everything)
- @kick = Puppet::Application[:kick]
- Puppet::Util::Log.stubs(:newdestination)
- Puppet::Util::Log.stubs(:level=)
+ confine "Kick's eventloops can only start on POSIX" => Puppet.features.posix?
+
+ before :each do
+ require 'puppet/util/ldap/connection'
+ Puppet::Util::Ldap::Connection.stubs(:new).returns(stub_everything)
+ @kick = Puppet::Application[:kick]
+ Puppet::Util::Log.stubs(:newdestination)
+ Puppet::Util::Log.stubs(:level=)
+ end
+
+ describe ".new" do
+ it "should take a command-line object as an argument" do
+ command_line = stub_everything "command_line"
+ lambda{ Puppet::Application::Kick.new( command_line ) }.should_not raise_error
end
+ end
- describe ".new" do
- it "should take a command-line object as an argument" do
- command_line = stub_everything "command_line"
- lambda{ Puppet::Application::Kick.new( command_line ) }.should_not raise_error
- end
- end
+ it "should ask Puppet::Application to not parse Puppet configuration file" do
+ @kick.should_parse_config?.should be_false
+ end
- it "should ask Puppet::Application to not parse Puppet configuration file" do
- @kick.should_parse_config?.should be_false
- end
+ it "should declare a main command" do
+ @kick.should respond_to(:main)
+ end
- it "should declare a main command" do
- @kick.should respond_to(:main)
- end
+ it "should declare a test command" do
+ @kick.should respond_to(:test)
+ end
- it "should declare a test command" do
- @kick.should respond_to(:test)
- end
+ it "should declare a preinit block" do
+ @kick.should respond_to(:preinit)
+ end
- it "should declare a preinit block" do
- @kick.should respond_to(:preinit)
+ describe "during preinit" do
+ before :each do
+ @kick.stubs(:trap)
end
- describe "during preinit" do
- before :each do
- @kick.stubs(:trap)
- end
-
- it "should catch INT and TERM" do
- @kick.stubs(:trap).with { |arg,block| arg == :INT or arg == :TERM }
+ it "should catch INT and TERM" do
+ @kick.stubs(:trap).with { |arg,block| arg == :INT or arg == :TERM }
- @kick.preinit
- end
+ @kick.preinit
+ end
- it "should set parallel option to 1" do
- @kick.preinit
+ it "should set parallel option to 1" do
+ @kick.preinit
- @kick.options[:parallel].should == 1
- end
+ @kick.options[:parallel].should == 1
+ end
- it "should set verbose by default" do
- @kick.preinit
+ it "should set verbose by default" do
+ @kick.preinit
- @kick.options[:verbose].should be_true
- end
+ @kick.options[:verbose].should be_true
+ end
- it "should set fqdn by default" do
- @kick.preinit
+ it "should set fqdn by default" do
+ @kick.preinit
- @kick.options[:fqdn].should be_true
- end
+ @kick.options[:fqdn].should be_true
+ end
- it "should set ignoreschedules to 'false'" do
- @kick.preinit
+ it "should set ignoreschedules to 'false'" do
+ @kick.preinit
- @kick.options[:ignoreschedules].should be_false
- end
+ @kick.options[:ignoreschedules].should be_false
+ end
- it "should set foreground to 'false'" do
- @kick.preinit
+ it "should set foreground to 'false'" do
+ @kick.preinit
- @kick.options[:foreground].should be_false
- end
+ @kick.options[:foreground].should be_false
end
+ end
- describe "when applying options" do
+ describe "when applying options" do
- before do
- @kick.preinit
- end
+ before do
+ @kick.preinit
+ end
- [:all, :foreground, :debug, :ping, :test].each do |option|
- it "should declare handle_#{option} method" do
- @kick.should respond_to("handle_#{option}".to_sym)
- end
+ [:all, :foreground, :debug, :ping, :test].each do |option|
+ it "should declare handle_#{option} method" do
+ @kick.should respond_to("handle_#{option}".to_sym)
+ end
- it "should store argument value when calling handle_#{option}" do
- @kick.options.expects(:[]=).with(option, 'arg')
- @kick.send("handle_#{option}".to_sym, 'arg')
- end
- end
+ it "should store argument value when calling handle_#{option}" do
+ @kick.options.expects(:[]=).with(option, 'arg')
+ @kick.send("handle_#{option}".to_sym, 'arg')
+ end
+ end
- it "should add to the host list with the host option" do
- @kick.handle_host('host')
+ it "should add to the host list with the host option" do
+ @kick.handle_host('host')
- @kick.hosts.should == ['host']
- end
+ @kick.hosts.should == ['host']
+ end
- it "should add to the tag list with the tag option" do
- @kick.handle_tag('tag')
+ it "should add to the tag list with the tag option" do
+ @kick.handle_tag('tag')
- @kick.tags.should == ['tag']
- end
+ @kick.tags.should == ['tag']
+ end
- it "should add to the class list with the class option" do
- @kick.handle_class('class')
+ it "should add to the class list with the class option" do
+ @kick.handle_class('class')
- @kick.classes.should == ['class']
- end
+ @kick.classes.should == ['class']
end
+ end
- describe "during setup" do
+ describe "during setup" do
- before :each do
- @kick.classes = []
- @kick.tags = []
- @kick.hosts = []
- Puppet::Log.stubs(:level=)
- @kick.stubs(:trap)
- @kick.stubs(:puts)
- Puppet.stubs(:parse_config)
+ before :each do
+ @kick.classes = []
+ @kick.tags = []
+ @kick.hosts = []
+ Puppet::Log.stubs(:level=)
+ @kick.stubs(:trap)
+ @kick.stubs(:puts)
+ Puppet.stubs(:parse_config)
+
+ @kick.options.stubs(:[]).with(any_parameters)
+ end
- @kick.options.stubs(:[]).with(any_parameters)
- end
+ it "should set log level to debug if --debug was passed" do
+ @kick.options.stubs(:[]).with(:debug).returns(true)
- it "should set log level to debug if --debug was passed" do
- @kick.options.stubs(:[]).with(:debug).returns(true)
+ Puppet::Log.expects(:level=).with(:debug)
- Puppet::Log.expects(:level=).with(:debug)
+ @kick.setup
+ end
- @kick.setup
- end
+ it "should set log level to info if --verbose was passed" do
+ @kick.options.stubs(:[]).with(:verbose).returns(true)
- it "should set log level to info if --verbose was passed" do
- @kick.options.stubs(:[]).with(:verbose).returns(true)
+ Puppet::Log.expects(:level=).with(:info)
- Puppet::Log.expects(:level=).with(:info)
+ @kick.setup
+ end
- @kick.setup
- end
+ it "should Parse puppet config" do
+ Puppet.expects(:parse_config)
- it "should Parse puppet config" do
- Puppet.expects(:parse_config)
+ @kick.setup
+ end
- @kick.setup
- end
+ describe "when using the ldap node terminus" do
+ before :each do
+ Puppet.stubs(:[]).with(:node_terminus).returns("ldap")
+ end
- describe "when using the ldap node terminus" do
- before :each do
- Puppet.stubs(:[]).with(:node_terminus).returns("ldap")
- end
+ it "should pass the fqdn option to search" do
+ @kick.options.stubs(:[]).with(:fqdn).returns(:something)
+ @kick.options.stubs(:[]).with(:all).returns(true)
+ @kick.stubs(:puts)
- it "should pass the fqdn option to search" do
- @kick.options.stubs(:[]).with(:fqdn).returns(:something)
- @kick.options.stubs(:[]).with(:all).returns(true)
- @kick.stubs(:puts)
+ Puppet::Node.expects(:search).with("whatever",:fqdn => :something).returns([])
- Puppet::Node.expects(:search).with("whatever",:fqdn => :something).returns([])
+ @kick.setup
+ end
- @kick.setup
- end
+ it "should search for all nodes if --all" do
+ @kick.options.stubs(:[]).with(:all).returns(true)
+ @kick.stubs(:puts)
- it "should search for all nodes if --all" do
- @kick.options.stubs(:[]).with(:all).returns(true)
- @kick.stubs(:puts)
+ Puppet::Node.expects(:search).with("whatever",:fqdn => nil).returns([])
- Puppet::Node.expects(:search).with("whatever",:fqdn => nil).returns([])
+ @kick.setup
+ end
- @kick.setup
- end
+ it "should search for nodes including given classes" do
+ @kick.options.stubs(:[]).with(:all).returns(false)
+ @kick.stubs(:puts)
+ @kick.classes = ['class']
- it "should search for nodes including given classes" do
- @kick.options.stubs(:[]).with(:all).returns(false)
- @kick.stubs(:puts)
- @kick.classes = ['class']
+ Puppet::Node.expects(:search).with("whatever", :class => "class", :fqdn => nil).returns([])
- Puppet::Node.expects(:search).with("whatever", :class => "class", :fqdn => nil).returns([])
+ @kick.setup
+ end
+ end
- @kick.setup
- end
- end
+ describe "when using regular nodes" do
+ it "should fail if some classes have been specified" do
+ $stderr.stubs(:puts)
+ @kick.classes = ['class']
- describe "when using regular nodes" do
- it "should fail if some classes have been specified" do
- $stderr.stubs(:puts)
- @kick.classes = ['class']
+ @kick.expects(:exit).with(24)
- @kick.expects(:exit).with(24)
+ @kick.setup
+ end
+ end
+ end
- @kick.setup
- end
- end
+ describe "when running" do
+ before :each do
+ @kick.stubs(:puts)
end
- describe "when running" do
- before :each do
- @kick.stubs(:puts)
- end
+ it "should dispatch to test if --test is used" do
+ @kick.options.stubs(:[]).with(:test).returns(true)
- it "should dispatch to test if --test is used" do
- @kick.options.stubs(:[]).with(:test).returns(true)
+ @kick.expects(:test)
+ @kick.run_command
+ end
- @kick.expects(:test)
- @kick.run_command
- end
+ it "should dispatch to main if --test is not used" do
+ @kick.options.stubs(:[]).with(:test).returns(false)
- it "should dispatch to main if --test is not used" do
- @kick.options.stubs(:[]).with(:test).returns(false)
+ @kick.expects(:main)
+ @kick.run_command
+ end
- @kick.expects(:main)
- @kick.run_command
- end
+ describe "the test command" do
+ it "should exit with exit code 0 " do
+ @kick.expects(:exit).with(0)
- describe "the test command" do
- it "should exit with exit code 0 " do
- @kick.expects(:exit).with(0)
+ @kick.test
+ end
+ end
- @kick.test
- end
+ describe "the main command" do
+ before :each do
+ @kick.options.stubs(:[]).with(:parallel).returns(1)
+ @kick.options.stubs(:[]).with(:ping).returns(false)
+ @kick.options.stubs(:[]).with(:ignoreschedules).returns(false)
+ @kick.options.stubs(:[]).with(:foreground).returns(false)
+ @kick.options.stubs(:[]).with(:debug).returns(false)
+ @kick.stubs(:print)
+ @kick.stubs(:exit)
+ @kick.preinit
+ @kick.stubs(:parse_options)
+ @kick.setup
+ $stderr.stubs(:puts)
+ end
+
+ it "should create as much childs as --parallel" do
+ @kick.options.stubs(:[]).with(:parallel).returns(3)
+ @kick.hosts = ['host1', 'host2', 'host3']
+ @kick.stubs(:exit).raises(SystemExit)
+ Process.stubs(:wait).returns(1).then.returns(2).then.returns(3).then.raises(Errno::ECHILD)
+
+ @kick.expects(:fork).times(3).returns(1).then.returns(2).then.returns(3)
+
+ lambda { @kick.main }.should raise_error
+ end
+
+ it "should delegate to run_for_host per host" do
+ @kick.hosts = ['host1', 'host2']
+ @kick.stubs(:exit).raises(SystemExit)
+ @kick.stubs(:fork).returns(1).yields
+ Process.stubs(:wait).returns(1).then.raises(Errno::ECHILD)
+
+ @kick.expects(:run_for_host).times(2)
+
+ lambda { @kick.main }.should raise_error
+ end
+
+ describe "during call of run_for_host" do
+ before do
+ require 'puppet/run'
+ options = {
+ :background => true, :ignoreschedules => false, :tags => []
+ }
+ @kick.preinit
+ @agent_run = Puppet::Run.new( options.dup )
+ @agent_run.stubs(:status).returns("success")
+
+ Puppet::Run.indirection.expects(:terminus_class=).with( :rest )
+ Puppet::Run.expects(:new).with( options ).returns(@agent_run)
end
- describe "the main command" do
- before :each do
- @kick.options.stubs(:[]).with(:parallel).returns(1)
- @kick.options.stubs(:[]).with(:ping).returns(false)
- @kick.options.stubs(:[]).with(:ignoreschedules).returns(false)
- @kick.options.stubs(:[]).with(:foreground).returns(false)
- @kick.options.stubs(:[]).with(:debug).returns(false)
- @kick.stubs(:print)
- @kick.stubs(:exit)
- @kick.preinit
- @kick.stubs(:parse_options)
- @kick.setup
- $stderr.stubs(:puts)
- end
-
- it "should create as much childs as --parallel" do
- @kick.options.stubs(:[]).with(:parallel).returns(3)
- @kick.hosts = ['host1', 'host2', 'host3']
- @kick.stubs(:exit).raises(SystemExit)
- Process.stubs(:wait).returns(1).then.returns(2).then.returns(3).then.raises(Errno::ECHILD)
-
- @kick.expects(:fork).times(3).returns(1).then.returns(2).then.returns(3)
-
- lambda { @kick.main }.should raise_error
- end
-
- it "should delegate to run_for_host per host" do
- @kick.hosts = ['host1', 'host2']
- @kick.stubs(:exit).raises(SystemExit)
- @kick.stubs(:fork).returns(1).yields
- Process.stubs(:wait).returns(1).then.raises(Errno::ECHILD)
+ it "should call run on a Puppet::Run for the given host" do
+ @agent_run.expects(:save).with('https://host:8139/production/run/host').returns(@agent_run)
- @kick.expects(:run_for_host).times(2)
-
- lambda { @kick.main }.should raise_error
- end
-
- describe "during call of run_for_host" do
- before do
- require 'puppet/run'
- options = {
- :background => true, :ignoreschedules => false, :tags => []
- }
- @kick.preinit
- @agent_run = Puppet::Run.new( options.dup )
- @agent_run.stubs(:status).returns("success")
-
- Puppet::Run.indirection.expects(:terminus_class=).with( :rest )
- Puppet::Run.expects(:new).with( options ).returns(@agent_run)
- end
-
- it "should call run on a Puppet::Run for the given host" do
- @agent_run.expects(:save).with('https://host:8139/production/run/host').returns(@agent_run)
-
- @kick.run_for_host('host')
- end
+ @kick.run_for_host('host')
+ end
- it "should exit the child with 0 on success" do
- @agent_run.stubs(:status).returns("success")
+ it "should exit the child with 0 on success" do
+ @agent_run.stubs(:status).returns("success")
- @kick.expects(:exit).with(0)
+ @kick.expects(:exit).with(0)
- @kick.run_for_host('host')
- end
+ @kick.run_for_host('host')
+ end
- it "should exit the child with 3 on running" do
- @agent_run.stubs(:status).returns("running")
+ it "should exit the child with 3 on running" do
+ @agent_run.stubs(:status).returns("running")
- @kick.expects(:exit).with(3)
+ @kick.expects(:exit).with(3)
- @kick.run_for_host('host')
- end
+ @kick.run_for_host('host')
+ end
- it "should exit the child with 12 on unknown answer" do
- @agent_run.stubs(:status).returns("whatever")
+ it "should exit the child with 12 on unknown answer" do
+ @agent_run.stubs(:status).returns("whatever")
- @kick.expects(:exit).with(12)
+ @kick.expects(:exit).with(12)
- @kick.run_for_host('host')
- end
- end
+ @kick.run_for_host('host')
end
+ end
end
+ end
end