Skip to content

Commit

Permalink
Correct spec errors
Browse files Browse the repository at this point in the history
  • Loading branch information
marcparadise committed Jun 25, 2012
1 parent 0aeb19d commit fa59609
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
19 changes: 5 additions & 14 deletions chef/lib/chef/provider/service/freebsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def load_current_resource
return
end
Chef::Log.debug("#{@current_resource} found at #{@init_command}")

determine_current_status!

# Default to disabled if the service doesn't currently exist
# at all
var_name = service_enable_variable_name
Expand Down Expand Up @@ -109,6 +107,7 @@ def stop_service

def restart_service
if @new_resource.restart_command

super
elsif @new_resource.supports[:restart]
shell_out!("#{@init_command} fastrestart")
Expand Down Expand Up @@ -147,19 +146,11 @@ def service_enable_variable_name
# We should get the service name from rcvar.
Chef::Log.debug("name=\"service\" not found at #{@init_command}. falling back to rcvar")
sn = shell_out!("#{@init_command} rcvar").stdout[/(\w+_enable)=/, 1]
if sn
return sn
else
# WHYRUN NOTE:
# In why-run mode, we are no longer guaranteed that this file exists -
# however, we can't let this block processing. In a normal run
# we would be blocked from reaching this point, so it's safe
# to work around it for why-run mode
return nil
end
else
return @new_resource.service_name
return sn
end
# Fallback allows us to keep running in whyrun mode when
# the script does not exist.
@new_resource.service_name
end

def set_service_enable(value)
Expand Down
19 changes: 12 additions & 7 deletions chef/spec/unit/provider/service/freebsd_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
rcvar=`set_rcvar`
RC_SAMPLE
::File.stub!(:open).with("/usr/local/etc/rc.d/#{@new_resource.service_name}").and_return(@rc_with_name)
@provider.stub(:service_enable_variable_name).and_return nil

end

it "should create a current resource with the name of the new resource" do
Expand Down Expand Up @@ -91,11 +93,10 @@
end

it "should set running to false if the status command returns anything except 0" do
# TODO this may be altered slightly after it's whyrunified
@provider.should_receive(:shell_out).with("/usr/local/etc/rc.d/#{@current_resource.service_name} status").and_raise(Mixlib::ShellOut::ShellCommandFailed)
@current_resource.should_receive(:running).with(false)
@provider.load_current_resource
@provider.current_resource.running.should be_false
# @provider.current_resource.running.should be_false
end
end

Expand Down Expand Up @@ -126,7 +127,7 @@
describe "when executing assertions" do
it "should verify that /etc/rc.conf exists" do
::File.should_receive(:exists?).with("/etc/rc.conf")
@provider.stub!(:service_enable_variable_name).and_return("apache22_enable")
@provider.stub!(:service_enable_variable_name).and_return("#{@current_resource.service_name}_enable")
@provider.load_current_resource
end

Expand All @@ -151,11 +152,13 @@
@provider.instance_variable_get("@rcd_script_found").should be_true
@provider.define_resource_requirements
lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service,
'Could not find name="service" line in /usr/local/etc/rc.d/apache22')
"Could not find the service name in /usr/local/etc/rc.d/#{@current_resource.service_name} and rcvar")
end

it "should throw an exception if service line is missing from rc.d script" do

pending "not implemented" do
false.should be_true
end
end

end
Expand Down Expand Up @@ -261,7 +264,7 @@
@rcvar_stdout = <<RCVAR_SAMPLE
# apache22
#
# apache22_enable="YES"
# #{@current_resource.service_name}_enable="YES"
# (default: "")
RCVAR_SAMPLE
@status = mock(:stdout => @rcvar_stdout, :exitstatus => 0)
Expand All @@ -270,6 +273,7 @@

it "should get the service name from rcvar if the rcscript does not have a name variable" do
@provider.load_current_resource
@provider.unstub!(:service_enable_variable_name)
@provider.service_enable_variable_name.should == "#{@current_resource.service_name}_enable"
end

Expand All @@ -291,7 +295,8 @@

it "should raise an exception if rcvar does not return foobar_enable" do
@provider.load_current_resource
lambda { @provider.service_enable_variable_name }.should raise_error(Chef::Exceptions::Service)
@provider.define_resource_requirements
lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service)
end
end
end
Expand Down

0 comments on commit fa59609

Please sign in to comment.