summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2009-09-03 22:05:11 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-09-05 09:24:29 +1000
commitd45812bc31a5a4517bbafb50fc7f9a15fca8d0a9 (patch)
treeb749a690101f53a382ae6975930a3f60916ac25f /spec
parentaba2f6600062c6935b65ebc2eeae0802e1f89a89 (diff)
downloadpuppet-d45812bc31a5a4517bbafb50fc7f9a15fca8d0a9.tar.gz
puppet-d45812bc31a5a4517bbafb50fc7f9a15fca8d0a9.tar.xz
puppet-d45812bc31a5a4517bbafb50fc7f9a15fca8d0a9.zip
Refactoring tests to reduce code size, increase coverage, and make
Luke happy.
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/provider/service/init.rb79
-rw-r--r--spec/unit/provider/service/redhat.rb81
2 files changed, 49 insertions, 111 deletions
diff --git a/spec/unit/provider/service/init.rb b/spec/unit/provider/service/init.rb
index 297768e33..0bfeb9a18 100644
--- a/spec/unit/provider/service/init.rb
+++ b/spec/unit/provider/service/init.rb
@@ -9,41 +9,18 @@ provider_class = Puppet::Type.type(:service).provider(:init)
describe provider_class do
- before(:each) do
- # Create a mock resource
+ before :each do
@resource = stub 'resource'
-
- @provider = provider_class.new
- # A catch all; no parameters set
@resource.stubs(:[]).returns(nil)
-
- # But set name, source and path (because we won't run
- # the thing that will fetch the resource path from the provider)
@resource.stubs(:[]).with(:name).returns "myservice"
- @resource.stubs(:[]).with(:ensure).returns :enabled
+# @resource.stubs(:[]).with(:ensure).returns :enabled
@resource.stubs(:[]).with(:path).returns ["/service/path","/alt/service/path"]
- @resource.stubs(:ref).returns "Service[myservice]"
+# @resource.stubs(:ref).returns "Service[myservice]"
- @provider.stubs(:resource).returns @resource
+ @provider = provider_class.new
@provider.resource = @resource
end
- it "should have a start method" do
- @provider.should respond_to(:start)
- end
-
- it "should have a stop method" do
- @provider.should respond_to(:stop)
- end
-
- it "should have a restart method" do
- @provider.should respond_to(:restart)
- end
-
- it "should have a status method" do
- @provider.should respond_to(:status)
- end
-
describe "when serching for the init script" do
it "should be able to find the init script in the service path" do
File.expects(:stat).with("/service/path/myservice").returns true
@@ -63,17 +40,23 @@ describe provider_class do
File.stubs(:stat).with("/service/path/myservice").returns true
end
- describe "when starting" do
- it "should execute the init script with start" do
- @provider.expects(:texecute).with(:start, ['/service/path/myservice', :start], true).returns("")
- @provider.start
+ [:start, :stop, :status, :restart].each do |method|
+ it "should have a #{method} method" do
+ @provider.should respond_to(method)
end
- end
+ describe "when running #{method}" do
+
+ it "should use any provided explicit command" do
+ @resource.stubs(:[]).with(method).returns "/user/specified/command"
+ @provider.expects(:execute).with { |command, *args| command == ["/user/specified/command"] }
+ @provider.send(method)
+ end
- describe "when stopping" do
- it "should execute the init script with stop" do
- @provider.expects(:texecute).with(:stop, ['/service/path/myservice', :stop], true).returns("")
- @provider.stop
+ it "should pass #{method} to the init script when no explicit command is provided" do
+ @resource.stubs(:[]).with("has#{method}".intern).returns :true
+ @provider.expects(:execute).with { |command, *args| command == ["/service/path/myservice",method]}
+ @provider.send(method)
+ end
end
end
@@ -111,24 +94,12 @@ describe provider_class do
end
end
- describe "when restarting" do
- describe "when hasrestart is :true" do
- before :each do
- @resource.stubs(:[]).with(:hasrestart).returns :true
- end
- it "should execute the command" do
- @provider.expects(:texecute).with(:restart, ['/service/path/myservice', :restart], true).returns("")
- $?.stubs(:exitstatus).returns(0)
- @provider.restart
- end
- end
- describe "when hasrestart is not :true" do
- it "should stop and restart the process" do
- @provider.expects(:texecute).with(:stop, ['/service/path/myservice', :stop ], true).returns("")
- @provider.expects(:texecute).with(:start,['/service/path/myservice', :start], true).returns("")
- $?.stubs(:exitstatus).returns(0)
- @provider.restart
- end
+ describe "when restarting and hasrestart is not :true" do
+ it "should stop and restart the process" do
+ @provider.expects(:texecute).with(:stop, ['/service/path/myservice', :stop ], true).returns("")
+ @provider.expects(:texecute).with(:start,['/service/path/myservice', :start], true).returns("")
+ $?.stubs(:exitstatus).returns(0)
+ @provider.restart
end
end
end
diff --git a/spec/unit/provider/service/redhat.rb b/spec/unit/provider/service/redhat.rb
index df2c93f57..eed8c9bea 100644
--- a/spec/unit/provider/service/redhat.rb
+++ b/spec/unit/provider/service/redhat.rb
@@ -9,39 +9,13 @@ provider_class = Puppet::Type.type(:service).provider(:redhat)
describe provider_class do
- before(:each) do
- # Create a mock resource
+ before :each do
@resource = stub 'resource'
-
- @provider = provider_class.new
- # A catch all; no parameters set
@resource.stubs(:[]).returns(nil)
-
- # But set name, source and path (because we won't run
- # the thing that will fetch the resource path from the provider)
@resource.stubs(:[]).with(:name).returns "myservice"
- @resource.stubs(:[]).with(:ensure).returns :enabled
- @resource.stubs(:[]).with(:path).returns ["/service/path","/alt/service/path"]
- @resource.stubs(:ref).returns "Service[myservice]"
-
- @provider.stubs(:resource).returns @resource
- @provider.resource = @resource
- end
- it "should have a start method" do
- @provider.should respond_to(:start)
- end
-
- it "should have a stop method" do
- @provider.should respond_to(:stop)
- end
-
- it "should have a restart method" do
- @provider.should respond_to(:restart)
- end
-
- it "should have a status method" do
- @provider.should respond_to(:status)
+ @provider = provider_class.new
+ @provider.resource = @resource
end
it "should have an enabled? method" do
@@ -56,17 +30,23 @@ describe provider_class do
@provider.should respond_to(:disable)
end
- describe "when starting" do
- it "should execute the service script with start" do
- @provider.expects(:texecute).with(:start, ['/sbin/service', 'myservice', 'start'], true)
- @provider.start
+ [:start, :stop, :status, :restart].each do |method|
+ it "should have a #{method} method" do
+ @provider.should respond_to(method)
end
- end
+ describe "when running #{method}" do
+
+ it "should use any provided explicit command" do
+ @resource.stubs(:[]).with(method).returns "/user/specified/command"
+ @provider.expects(:execute).with { |command, *args| command == ["/user/specified/command"] }
+ @provider.send(method)
+ end
- describe "when stopping" do
- it "should execute the init script with stop" do
- @provider.expects(:texecute).with(:stop, ['/sbin/service', 'myservice', 'stop'], true)
- @provider.stop
+ it "should execute the service script with #{method} when no explicit command is provided" do
+ @resource.stubs(:[]).with("has#{method}".intern).returns :true
+ @provider.expects(:execute).with { |command, *args| command == ['/sbin/service', 'myservice', method.to_s]}
+ @provider.send(method)
+ end
end
end
@@ -75,7 +55,7 @@ describe provider_class do
before :each do
@resource.stubs(:[]).with(:hasstatus).returns :true
end
- it "should execute the command" do
+ it "should execute the service script with fail_on_failure false" do
@provider.expects(:texecute).with(:status, ['/sbin/service', 'myservice', 'status'], false)
@provider.status
end
@@ -104,24 +84,11 @@ describe provider_class do
end
end
- describe "when restarting" do
- describe "when hasrestart is :true" do
- before :each do
- @resource.stubs(:[]).with(:hasrestart).returns :true
- end
- it "should execute the command" do
- @provider.expects(:texecute).with(:restart, ['/sbin/service', 'myservice', 'restart'], true)
- $?.stubs(:exitstatus).returns(0)
- @provider.restart
- end
- end
- describe "when hasrestart is not :true" do
- it "should stop and restart the process" do
- @provider.expects(:texecute).with(:stop, ['/sbin/service', 'myservice', 'stop'], true)
- @provider.expects(:texecute).with(:start, ['/sbin/service', 'myservice', 'start'], true)
- $?.stubs(:exitstatus).returns(0)
- @provider.restart
- end
+ describe "when restarting and hasrestart is not :true" do
+ it "should stop and restart the process with the server script" do
+ @provider.expects(:texecute).with(:stop, ['/sbin/service', 'myservice', 'stop'], true)
+ @provider.expects(:texecute).with(:start, ['/sbin/service', 'myservice', 'start'], true)
+ @provider.restart
end
end
end