3
# Unit testing for the debian service provider
6
require File.dirname(__FILE__) + '/../../../spec_helper'
8
provider_class = Puppet::Type.type(:service).provider(:debian)
10
describe provider_class do
13
# Create a mock resource
14
@resource = stub 'resource'
16
@provider = provider_class.new
18
# A catch all; no parameters set
19
@resource.stubs(:[]).returns(nil)
21
# But set name, source and path
22
@resource.stubs(:[]).with(:name).returns "myservice"
23
@resource.stubs(:[]).with(:ensure).returns :enabled
24
@resource.stubs(:ref).returns "Service[myservice]"
26
@provider.resource = @resource
28
@provider.stubs(:command).with(:update_rc).returns "update_rc"
29
@provider.stubs(:command).with(:invoke_rc).returns "invoke_rc"
31
@provider.stubs(:update_rc)
32
@provider.stubs(:invoke_rc)
35
it "should have an enabled? method" do
36
@provider.should respond_to(:enabled?)
39
it "should have an enable method" do
40
@provider.should respond_to(:enable)
43
it "should have a disable method" do
44
@provider.should respond_to(:disable)
47
describe "when enabling" do
48
it "should call update-rc.d twice" do
49
@provider.expects(:update_rc).twice
54
describe "when disabling" do
55
it "should call update-rc.d twice" do
56
@provider.expects(:update_rc).twice
61
describe "when checking whether it is enabled" do
62
it "should call Kernel.system() with the appropriate parameters" do
63
@provider.expects(:system).with("/usr/sbin/invoke-rc.d", "--query", @resource[:name], "start").once
67
it "should return true when invoke-rc.d exits with 104 status" do
68
@provider.stubs(:system)
69
$?.stubs(:exitstatus).returns(104)
70
@provider.enabled?.should == :true
73
it "should return true when invoke-rc.d exits with 106 status" do
74
@provider.stubs(:system)
75
$?.stubs(:exitstatus).returns(106)
76
@provider.enabled?.should == :true
79
# pick a range of non-[104.106] numbers, strings and booleans to test with.
80
[-100, -1, 0, 1, 100, "foo", "", :true, :false].each do |exitstatus|
81
it "should return false when invoke-rc.d exits with #{exitstatus} status" do
82
@provider.stubs(:system)
83
$?.stubs(:exitstatus).returns(exitstatus)
84
@provider.enabled?.should == :false