Skip to content

Commit 5c4ef76

Browse files
llaurentdanielsdeleo
authored andcommitted
duplicate code to handle both behaviors
1 parent 05f29ee commit 5c4ef76

1 file changed

Lines changed: 77 additions & 16 deletions

File tree

chef/spec/unit/provider/service/debian_service_spec.rb

Lines changed: 77 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,32 @@
3838
File.should_receive(:exists?).with("/usr/sbin/update-rc.d").and_return(false)
3939
lambda { @provider.assert_update_rcd_available }.should raise_error(Chef::Exceptions::Service)
4040
end
41-
42-
describe "when update-rc.d shows the init script linked to rc*.d/" do
41+
42+
describe "when using squeeze/earlier and update-rc.d shows the init script linked to rc*.d/" do
4343
before do
4444
@provider.stub!(:run_command)
4545
@provider.stub!(:assert_update_rcd_available)
4646
@status = mock("Status", :exitstatus => 0)
47-
48-
result=<<-UPDATE_RC_D_SUCCESS
49-
update-rc.d: using dependency based boot sequencing
47+
48+
@stdout = StringIO.new("update-rc.d: using dependency based boot sequencing")
49+
result2=<<-UPDATE_RC_D_SUCCESS
5050
insserv: remove service /etc/init.d/../rc0.d/K20chef-client
5151
insserv: remove service /etc/init.d/../rc1.d/K20chef-client
5252
insserv: remove service /etc/init.d/../rc2.d/S20chef-client
5353
insserv: remove service /etc/init.d/../rc3.d/S20chef-client
5454
insserv: remove service /etc/init.d/../rc4.d/S20chef-client
5555
insserv: remove service /etc/init.d/../rc5.d/S20chef-client
5656
insserv: remove service /etc/init.d/../rc6.d/K20chef-client
57-
UPDATE_RC_D_SUCCESS
58-
@stdout = StringIO.new(result)
59-
@stderr = StringIO.new(result)
57+
insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop
58+
UPDATE_RC_D_SUCCESS
59+
@stderr = StringIO.new(result2)
6060
@provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
6161
end
6262

6363
it "says the service is enabled" do
6464
@provider.service_currently_enabled?.should be_true
6565
end
66-
66+
6767
it "stores the 'enabled' state" do
6868
Chef::Resource::Service.stub!(:new).and_return(@current_resource)
6969
@provider.load_current_resource.should equal(@current_resource)
@@ -81,17 +81,80 @@
8181
"5"=>[:start, "20"]}
8282
@provider.current_resource.priority.should == expected_priorities
8383
end
84-
8584
end
8685

87-
describe "when update-rc.d shows the init script isn't linked to rc*.d" do
86+
describe "when using squeeze/earlier and update-rc.d shows the init script isn't linked to rc*.d" do
8887
before do
8988
@provider.stub!(:run_command)
9089
@provider.stub!(:assert_update_rcd_available)
9190
@status = mock("Status", :exitstatus => 0)
92-
result = "update-rc.d: using dependency based boot sequencing"
91+
@stdout = StringIO.new("update-rc.d: using dependency based boot sequencing")
92+
@stderr = StringIO.new("")
93+
@provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
94+
end
95+
96+
it "says the service is disabled" do
97+
@provider.service_currently_enabled?.should be_false
98+
end
99+
100+
it "stores the 'disabled' state" do
101+
Chef::Resource::Service.stub!(:new).and_return(@current_resource)
102+
@provider.load_current_resource.should equal(@current_resource)
103+
@current_resource.enabled.should be_false
104+
end
105+
end
106+
107+
describe "when using lenny/older and update-rc.d shows the init script linked to rc*.d/" do
108+
before do
109+
@provider.stub!(:run_command)
110+
@provider.stub!(:assert_update_rcd_available)
111+
@status = mock("Status", :exitstatus => 0)
112+
113+
result=<<-UPDATE_RC_D_SUCCESS
114+
Removing any system startup links for /etc/init.d/chef ...
115+
/etc/rc0.d/K20chef
116+
/etc/rc1.d/K20chef
117+
/etc/rc2.d/S20chef
118+
/etc/rc3.d/S20chef
119+
/etc/rc4.d/S20chef
120+
/etc/rc5.d/S20chef
121+
/etc/rc6.d/K20chef
122+
UPDATE_RC_D_SUCCESS
93123
@stdout = StringIO.new(result)
94-
@stderr = StringIO.new(result)
124+
@stderr = StringIO.new("")
125+
@provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
126+
end
127+
128+
it "says the service is enabled" do
129+
@provider.service_currently_enabled?.should be_true
130+
end
131+
132+
it "stores the 'enabled' state" do
133+
Chef::Resource::Service.stub!(:new).and_return(@current_resource)
134+
@provider.load_current_resource.should equal(@current_resource)
135+
@current_resource.enabled.should be_true
136+
end
137+
138+
it "stores the start/stop priorities of the service" do
139+
@provider.load_current_resource
140+
expected_priorities = {"6"=>[:stop, "20"],
141+
"0"=>[:stop, "20"],
142+
"1"=>[:stop, "20"],
143+
"2"=>[:start, "20"],
144+
"3"=>[:start, "20"],
145+
"4"=>[:start, "20"],
146+
"5"=>[:start, "20"]}
147+
@provider.current_resource.priority.should == expected_priorities
148+
end
149+
end
150+
151+
describe "when using lenny/older and update-rc.d shows the init script isn't linked to rc*.d" do
152+
before do
153+
@provider.stub!(:run_command)
154+
@provider.stub!(:assert_update_rcd_available)
155+
@status = mock("Status", :exitstatus => 0)
156+
@stdout = StringIO.new(" Removing any system startup links for /etc/init.d/chef ...")
157+
@stderr = StringIO.new("")
95158
@provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
96159
end
97160

@@ -105,7 +168,7 @@
105168
@current_resource.enabled.should be_false
106169
end
107170
end
108-
171+
109172
describe "when update-rc.d fails" do
110173
before do
111174
@status = mock("Status", :exitstatus => -1)
@@ -115,7 +178,6 @@
115178
it "raises an error" do
116179
lambda { @provider.service_currently_enabled? }.should raise_error(Chef::Exceptions::Service)
117180
end
118-
119181
end
120182

121183
describe "when enabling a service without priority" do
@@ -148,7 +210,6 @@
148210
end
149211

150212
describe "when disabling a service" do
151-
152213
it "should call update-rc.d 'service_name' disable" do
153214
@provider.should_receive(:run_command).with({:command => "/usr/sbin/update-rc.d #{@new_resource.service_name} disable"})
154215
@provider.disable_service()

0 commit comments

Comments
 (0)