summaryrefslogtreecommitdiffstats
path: root/spec/unit/daemon_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/daemon_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/daemon_spec.rb')
-rwxr-xr-xspec/unit/daemon_spec.rb430
1 files changed, 215 insertions, 215 deletions
diff --git a/spec/unit/daemon_spec.rb b/spec/unit/daemon_spec.rb
index a4fa64489..15320736c 100755
--- a/spec/unit/daemon_spec.rb
+++ b/spec/unit/daemon_spec.rb
@@ -4,303 +4,303 @@ require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/daemon'
def without_warnings
- flag = $VERBOSE
- $VERBOSE = nil
- yield
- $VERBOSE = flag
+ flag = $VERBOSE
+ $VERBOSE = nil
+ yield
+ $VERBOSE = flag
end
describe Puppet::Daemon do
- before do
- @daemon = Puppet::Daemon.new
- end
+ before do
+ @daemon = Puppet::Daemon.new
+ end
- it "should be able to manage an agent" do
- @daemon.should respond_to(:agent)
- end
+ it "should be able to manage an agent" do
+ @daemon.should respond_to(:agent)
+ end
- it "should be able to manage a network server" do
- @daemon.should respond_to(:server)
- end
+ it "should be able to manage a network server" do
+ @daemon.should respond_to(:server)
+ end
- it "should reopen the Log logs when told to reopen logs" do
- Puppet::Util::Log.expects(:reopen)
- @daemon.reopen_logs
- end
+ it "should reopen the Log logs when told to reopen logs" do
+ Puppet::Util::Log.expects(:reopen)
+ @daemon.reopen_logs
+ end
- describe "when setting signal traps" do
- before do
- @daemon.stubs(:trap)
- end
+ describe "when setting signal traps" do
+ before do
+ @daemon.stubs(:trap)
+ end
- {:INT => :stop, :TERM => :stop, :HUP => :restart, :USR1 => :reload, :USR2 => :reopen_logs}.each do |signal, method|
- it "should log and call #{method} when it receives #{signal}" do
- @daemon.expects(:trap).with(signal).yields
+ {:INT => :stop, :TERM => :stop, :HUP => :restart, :USR1 => :reload, :USR2 => :reopen_logs}.each do |signal, method|
+ it "should log and call #{method} when it receives #{signal}" do
+ @daemon.expects(:trap).with(signal).yields
- Puppet.expects(:notice)
+ Puppet.expects(:notice)
- @daemon.expects(method)
+ @daemon.expects(method)
- @daemon.set_signal_traps
- end
- end
+ @daemon.set_signal_traps
+ end
end
+ end
- describe "when starting" do
- before do
- @daemon.stubs(:create_pidfile)
- @daemon.stubs(:set_signal_traps)
- EventLoop.current.stubs(:run)
- end
+ describe "when starting" do
+ before do
+ @daemon.stubs(:create_pidfile)
+ @daemon.stubs(:set_signal_traps)
+ EventLoop.current.stubs(:run)
+ end
- it "should fail if it has neither agent nor server" do
- lambda { @daemon.start }.should raise_error(Puppet::DevError)
- end
+ it "should fail if it has neither agent nor server" do
+ lambda { @daemon.start }.should raise_error(Puppet::DevError)
+ end
- it "should create its pidfile" do
- @daemon.stubs(:agent).returns stub('agent', :start => nil)
+ it "should create its pidfile" do
+ @daemon.stubs(:agent).returns stub('agent', :start => nil)
- @daemon.expects(:create_pidfile)
- @daemon.start
- end
+ @daemon.expects(:create_pidfile)
+ @daemon.start
+ end
- it "should start the agent if the agent is configured" do
- agent = mock 'agent'
- agent.expects(:start)
- @daemon.stubs(:agent).returns agent
+ it "should start the agent if the agent is configured" do
+ agent = mock 'agent'
+ agent.expects(:start)
+ @daemon.stubs(:agent).returns agent
- @daemon.start
- end
+ @daemon.start
+ end
- it "should start its server if one is configured" do
- server = mock 'server'
- server.expects(:start)
- @daemon.stubs(:server).returns server
+ it "should start its server if one is configured" do
+ server = mock 'server'
+ server.expects(:start)
+ @daemon.stubs(:server).returns server
- @daemon.start
- end
+ @daemon.start
+ end
- it "should let the current EventLoop run" do
- @daemon.stubs(:agent).returns stub('agent', :start => nil)
- EventLoop.current.expects(:run)
+ it "should let the current EventLoop run" do
+ @daemon.stubs(:agent).returns stub('agent', :start => nil)
+ EventLoop.current.expects(:run)
- @daemon.start
- end
+ @daemon.start
end
+ end
- describe "when stopping" do
- before do
- @daemon.stubs(:remove_pidfile)
- @daemon.stubs(:exit)
- Puppet::Util::Log.stubs(:close_all)
- # to make the global safe to mock, set it to a subclass of itself,
- # then restore it in an after pass
- without_warnings { Puppet::Application = Class.new(Puppet::Application) }
- end
+ describe "when stopping" do
+ before do
+ @daemon.stubs(:remove_pidfile)
+ @daemon.stubs(:exit)
+ Puppet::Util::Log.stubs(:close_all)
+ # to make the global safe to mock, set it to a subclass of itself,
+ # then restore it in an after pass
+ without_warnings { Puppet::Application = Class.new(Puppet::Application) }
+ end
- after do
- # restore from the superclass so we lose the stub garbage
- without_warnings { Puppet::Application = Puppet::Application.superclass }
- end
+ after do
+ # restore from the superclass so we lose the stub garbage
+ without_warnings { Puppet::Application = Puppet::Application.superclass }
+ end
- it "should stop its server if one is configured" do
- server = mock 'server'
- server.expects(:stop)
- @daemon.stubs(:server).returns server
+ it "should stop its server if one is configured" do
+ server = mock 'server'
+ server.expects(:stop)
+ @daemon.stubs(:server).returns server
- @daemon.stop
- end
+ @daemon.stop
+ end
- it 'should request a stop from Puppet::Application' do
- Puppet::Application.expects(:stop!)
- @daemon.stop
- end
+ it 'should request a stop from Puppet::Application' do
+ Puppet::Application.expects(:stop!)
+ @daemon.stop
+ end
- it "should remove its pidfile" do
- @daemon.expects(:remove_pidfile)
+ it "should remove its pidfile" do
+ @daemon.expects(:remove_pidfile)
- @daemon.stop
- end
+ @daemon.stop
+ end
- it "should close all logs" do
- Puppet::Util::Log.expects(:close_all)
+ it "should close all logs" do
+ Puppet::Util::Log.expects(:close_all)
- @daemon.stop
- end
+ @daemon.stop
+ end
- it "should exit unless called with ':exit => false'" do
- @daemon.expects(:exit)
- @daemon.stop
- end
+ it "should exit unless called with ':exit => false'" do
+ @daemon.expects(:exit)
+ @daemon.stop
+ end
- it "should not exit if called with ':exit => false'" do
- @daemon.expects(:exit).never
- @daemon.stop :exit => false
- end
+ it "should not exit if called with ':exit => false'" do
+ @daemon.expects(:exit).never
+ @daemon.stop :exit => false
end
+ end
- describe "when creating its pidfile" do
- it "should use an exclusive mutex" do
- Puppet.settings.expects(:value).with(:name).returns "me"
+ describe "when creating its pidfile" do
+ it "should use an exclusive mutex" do
+ Puppet.settings.expects(:value).with(:name).returns "me"
- sync = mock 'sync'
- Puppet::Util.expects(:sync).with("me").returns sync
+ sync = mock 'sync'
+ Puppet::Util.expects(:sync).with("me").returns sync
- sync.expects(:synchronize).with(Sync::EX)
- @daemon.create_pidfile
- end
+ sync.expects(:synchronize).with(Sync::EX)
+ @daemon.create_pidfile
+ end
- it "should lock the pidfile using the Pidlock class" do
- pidfile = mock 'pidfile'
+ it "should lock the pidfile using the Pidlock class" do
+ pidfile = mock 'pidfile'
- Puppet.settings.stubs(:value).with(:name).returns "eh"
- Puppet.settings.expects(:value).with(:pidfile).returns "/my/file"
+ Puppet.settings.stubs(:value).with(:name).returns "eh"
+ Puppet.settings.expects(:value).with(:pidfile).returns "/my/file"
- Puppet::Util::Pidlock.expects(:new).with("/my/file").returns pidfile
+ Puppet::Util::Pidlock.expects(:new).with("/my/file").returns pidfile
- pidfile.expects(:lock).returns true
- @daemon.create_pidfile
- end
+ pidfile.expects(:lock).returns true
+ @daemon.create_pidfile
+ end
- it "should fail if it cannot lock" do
- pidfile = mock 'pidfile'
+ it "should fail if it cannot lock" do
+ pidfile = mock 'pidfile'
- Puppet.settings.stubs(:value).with(:name).returns "eh"
- Puppet.settings.stubs(:value).with(:pidfile).returns "/my/file"
+ Puppet.settings.stubs(:value).with(:name).returns "eh"
+ Puppet.settings.stubs(:value).with(:pidfile).returns "/my/file"
- Puppet::Util::Pidlock.expects(:new).with("/my/file").returns pidfile
+ Puppet::Util::Pidlock.expects(:new).with("/my/file").returns pidfile
- pidfile.expects(:lock).returns false
+ pidfile.expects(:lock).returns false
- lambda { @daemon.create_pidfile }.should raise_error
- end
+ lambda { @daemon.create_pidfile }.should raise_error
end
+ end
- describe "when removing its pidfile" do
- it "should use an exclusive mutex" do
- Puppet.settings.expects(:value).with(:name).returns "me"
+ describe "when removing its pidfile" do
+ it "should use an exclusive mutex" do
+ Puppet.settings.expects(:value).with(:name).returns "me"
- sync = mock 'sync'
- Puppet::Util.expects(:sync).with("me").returns sync
+ sync = mock 'sync'
+ Puppet::Util.expects(:sync).with("me").returns sync
- sync.expects(:synchronize).with(Sync::EX)
- @daemon.remove_pidfile
- end
+ sync.expects(:synchronize).with(Sync::EX)
+ @daemon.remove_pidfile
+ end
- it "should do nothing if the pidfile is not present" do
- pidfile = mock 'pidfile', :locked? => false
- Puppet::Util::Pidlock.expects(:new).with("/my/file").returns pidfile
+ it "should do nothing if the pidfile is not present" do
+ pidfile = mock 'pidfile', :locked? => false
+ Puppet::Util::Pidlock.expects(:new).with("/my/file").returns pidfile
- Puppet.settings.stubs(:value).with(:name).returns "eh"
- Puppet.settings.stubs(:value).with(:pidfile).returns "/my/file"
+ Puppet.settings.stubs(:value).with(:name).returns "eh"
+ Puppet.settings.stubs(:value).with(:pidfile).returns "/my/file"
- pidfile.expects(:unlock).never
- @daemon.remove_pidfile
- end
+ pidfile.expects(:unlock).never
+ @daemon.remove_pidfile
+ end
- it "should unlock the pidfile using the Pidlock class" do
- pidfile = mock 'pidfile', :locked? => true
- Puppet::Util::Pidlock.expects(:new).with("/my/file").returns pidfile
- pidfile.expects(:unlock).returns true
+ it "should unlock the pidfile using the Pidlock class" do
+ pidfile = mock 'pidfile', :locked? => true
+ Puppet::Util::Pidlock.expects(:new).with("/my/file").returns pidfile
+ pidfile.expects(:unlock).returns true
- Puppet.settings.stubs(:value).with(:name).returns "eh"
- Puppet.settings.stubs(:value).with(:pidfile).returns "/my/file"
+ Puppet.settings.stubs(:value).with(:name).returns "eh"
+ Puppet.settings.stubs(:value).with(:pidfile).returns "/my/file"
- @daemon.remove_pidfile
- end
+ @daemon.remove_pidfile
+ end
- it "should warn if it cannot remove the pidfile" do
- pidfile = mock 'pidfile', :locked? => true
- Puppet::Util::Pidlock.expects(:new).with("/my/file").returns pidfile
- pidfile.expects(:unlock).returns false
+ it "should warn if it cannot remove the pidfile" do
+ pidfile = mock 'pidfile', :locked? => true
+ Puppet::Util::Pidlock.expects(:new).with("/my/file").returns pidfile
+ pidfile.expects(:unlock).returns false
- Puppet.settings.stubs(:value).with(:name).returns "eh"
- Puppet.settings.stubs(:value).with(:pidfile).returns "/my/file"
+ Puppet.settings.stubs(:value).with(:name).returns "eh"
+ Puppet.settings.stubs(:value).with(:pidfile).returns "/my/file"
- Puppet.expects :err
- @daemon.remove_pidfile
- end
+ Puppet.expects :err
+ @daemon.remove_pidfile
end
+ end
- describe "when reloading" do
- it "should do nothing if no agent is configured" do
- @daemon.reload
- end
+ describe "when reloading" do
+ it "should do nothing if no agent is configured" do
+ @daemon.reload
+ end
- it "should do nothing if the agent is running" do
- agent = mock 'agent'
- agent.expects(:running?).returns true
+ it "should do nothing if the agent is running" do
+ agent = mock 'agent'
+ agent.expects(:running?).returns true
- @daemon.stubs(:agent).returns agent
+ @daemon.stubs(:agent).returns agent
- @daemon.reload
- end
+ @daemon.reload
+ end
- it "should run the agent if one is available and it is not running" do
- agent = mock 'agent'
- agent.expects(:running?).returns false
- agent.expects :run
+ it "should run the agent if one is available and it is not running" do
+ agent = mock 'agent'
+ agent.expects(:running?).returns false
+ agent.expects :run
- @daemon.stubs(:agent).returns agent
+ @daemon.stubs(:agent).returns agent
- @daemon.reload
- end
+ @daemon.reload
end
+ end
- describe "when restarting" do
- before do
- without_warnings { Puppet::Application = Class.new(Puppet::Application) }
- end
+ describe "when restarting" do
+ before do
+ without_warnings { Puppet::Application = Class.new(Puppet::Application) }
+ end
- after do
- without_warnings { Puppet::Application = Puppet::Application.superclass }
- end
+ after do
+ without_warnings { Puppet::Application = Puppet::Application.superclass }
+ end
- it 'should set Puppet::Application.restart!' do
- Puppet::Application.expects(:restart!)
- @daemon.stubs(:reexec)
- @daemon.restart
- end
+ it 'should set Puppet::Application.restart!' do
+ Puppet::Application.expects(:restart!)
+ @daemon.stubs(:reexec)
+ @daemon.restart
+ end
- it "should reexec itself if no agent is available" do
- @daemon.expects(:reexec)
+ it "should reexec itself if no agent is available" do
+ @daemon.expects(:reexec)
- @daemon.restart
- end
+ @daemon.restart
+ end
- it "should reexec itself if the agent is not running" do
- agent = mock 'agent'
- agent.expects(:running?).returns false
- @daemon.stubs(:agent).returns agent
- @daemon.expects(:reexec)
+ it "should reexec itself if the agent is not running" do
+ agent = mock 'agent'
+ agent.expects(:running?).returns false
+ @daemon.stubs(:agent).returns agent
+ @daemon.expects(:reexec)
- @daemon.restart
- end
+ @daemon.restart
end
+ end
- describe "when reexecing it self" do
- before do
- @daemon.stubs(:exec)
- @daemon.stubs(:stop)
- end
+ describe "when reexecing it self" do
+ before do
+ @daemon.stubs(:exec)
+ @daemon.stubs(:stop)
+ end
- it "should fail if no argv values are available" do
- @daemon.expects(:argv).returns nil
- lambda { @daemon.reexec }.should raise_error(Puppet::DevError)
- end
+ it "should fail if no argv values are available" do
+ @daemon.expects(:argv).returns nil
+ lambda { @daemon.reexec }.should raise_error(Puppet::DevError)
+ end
- it "should shut down without exiting" do
- @daemon.argv = %w{foo}
- @daemon.expects(:stop).with(:exit => false)
+ it "should shut down without exiting" do
+ @daemon.argv = %w{foo}
+ @daemon.expects(:stop).with(:exit => false)
- @daemon.reexec
- end
+ @daemon.reexec
+ end
- it "should call 'exec' with the original executable and arguments" do
- @daemon.argv = %w{foo}
- @daemon.expects(:exec).with($0 + " foo")
+ it "should call 'exec' with the original executable and arguments" do
+ @daemon.argv = %w{foo}
+ @daemon.expects(:exec).with($0 + " foo")
- @daemon.reexec
- end
+ @daemon.reexec
end
+ end
end