diff options
author | deployable <matt@deployable.co> | 2014-05-21 09:44:23 +0100 |
---|---|---|
committer | deployable <matt@deployable.co> | 2014-05-21 09:44:23 +0100 |
commit | 5439694dcdfceb12add4a5409477e2e14296c457 (patch) | |
tree | e75271cc64890e31c81b63a98201f32dd5748748 /spec | |
parent | c9ba5a629e88cf51af240c711befbc1d093367ad (diff) | |
download | chef-5439694dcdfceb12add4a5409477e2e14296c457.tar.gz |
Fixed whitespace in changes.
Fixed deprecation warnings for `stub!` and `mock` in tests.
Added tests for `START_PENDING` and `STOP_PENDING` state to `stop_service` and `start_service`
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/provider/service/windows_spec.rb | 125 |
1 files changed, 83 insertions, 42 deletions
diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb index 69e942cf16..a007e7b984 100644 --- a/spec/unit/provider/service/windows_spec.rb +++ b/spec/unit/provider/service/windows_spec.rb @@ -31,11 +31,11 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do Win32::Service = Class.new Win32::Service::AUTO_START = 0x00000002 Win32::Service::DISABLED = 0x00000004 - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "running")) - Win32::Service.stub!(:config_info).with(@new_resource.service_name).and_return( - mock("ConfigStruct", :start_type => "auto start")) - Win32::Service.stub!(:exists?).and_return(true) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "running")) + Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + double("ConfigStruct", :start_type => "auto start")) + Win32::Service.stub(:exists?).and_return(true) end it "should set the current resources service name to the new resources service name" do @@ -59,9 +59,9 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do describe Chef::Provider::Service::Windows, "start_service" do before(:each) do - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "stopped"), - mock("StatusStruct", :current_state => "running")) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "stopped"), + double("StatusStruct", :current_state => "running")) end it "should call the start command if one is specified" do @@ -78,15 +78,15 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end it "should do nothing if the service does not exist" do - Win32::Service.stub!(:exists?).with(@new_resource.service_name).and_return(false) + Win32::Service.stub(:exists?).with(@new_resource.service_name).and_return(false) Win32::Service.should_not_receive(:start).with(@new_resource.service_name) @provider.start_service @new_resource.updated_by_last_action?.should be_false end it "should do nothing if the service is running" do - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "running")) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "running")) @provider.load_current_resource Win32::Service.should_not_receive(:start).with(@new_resource.service_name) @provider.start_service @@ -94,22 +94,43 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end it "should raise an error if the service is paused" do - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "paused")) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "paused")) @provider.load_current_resource Win32::Service.should_not_receive(:start).with(@new_resource.service_name) expect { @provider.start_service }.to raise_error( Chef::Exceptions::Service ) @new_resource.updated_by_last_action?.should be_false end + + it "should wait and continue if the service is in start_pending" do + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "start pending"), + double("StatusStruct", :current_state => "start pending"), + double("StatusStruct", :current_state => "running")) + @provider.load_current_resource + Win32::Service.should_not_receive(:start).with(@new_resource.service_name) + @provider.start_service + @new_resource.updated_by_last_action?.should be_false + end + it "should fail if the service is in stop_pending" do + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "stop pending")) + @provider.load_current_resource + Win32::Service.should_not_receive(:start).with(@new_resource.service_name) + expect { @provider.start_service }.to raise_error( Chef::Exceptions::Service ) + @new_resource.updated_by_last_action?.should be_false + end + end + describe Chef::Provider::Service::Windows, "stop_service" do before(:each) do - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "running"), - mock("StatusStruct", :current_state => "stopped")) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "running"), + double("StatusStruct", :current_state => "stopped")) end it "should call the stop command if one is specified" do @@ -126,15 +147,15 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end it "should do nothing if the service does not exist" do - Win32::Service.stub!(:exists?).with(@new_resource.service_name).and_return(false) + Win32::Service.stub(:exists?).with(@new_resource.service_name).and_return(false) Win32::Service.should_not_receive(:stop).with(@new_resource.service_name) @provider.stop_service @new_resource.updated_by_last_action?.should be_false end it "should do nothing if the service is stopped" do - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "stopped")) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "stopped")) @provider.load_current_resource Win32::Service.should_not_receive(:stop).with(@new_resource.service_name) @provider.stop_service @@ -142,14 +163,34 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end it "should raise an error if the service is paused" do - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "paused")) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "paused")) @provider.load_current_resource Win32::Service.should_not_receive(:start).with(@new_resource.service_name) - expect { @provider.start_service }.to raise_error( Chef::Exceptions::Service ) + expect { @provider.stop_service }.to raise_error( Chef::Exceptions::Service ) @new_resource.updated_by_last_action?.should be_false end + it "should wait and continue if the service is in stop_pending" do + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "stop pending"), + double("StatusStruct", :current_state => "stop pending"), + double("StatusStruct", :current_state => "stopped")) + @provider.load_current_resource + Win32::Service.should_not_receive(:stop).with(@new_resource.service_name) + @provider.stop_service + @new_resource.updated_by_last_action?.should be_false + end + + it "should fail if the service is in start_pending" do + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "start pending")) + @provider.load_current_resource + Win32::Service.should_not_receive(:stop).with(@new_resource.service_name) + expect { @provider.stop_service }.to raise_error( Chef::Exceptions::Service ) + @new_resource.updated_by_last_action?.should be_false + end + end describe Chef::Provider::Service::Windows, "restart_service" do @@ -162,11 +203,11 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end it "should stop then start the service if it is running" do - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "running"), - mock("StatusStruct", :current_state => "stopped"), - mock("StatusStruct", :current_state => "stopped"), - mock("StatusStruct", :current_state => "running")) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "running"), + double("StatusStruct", :current_state => "stopped"), + double("StatusStruct", :current_state => "stopped"), + double("StatusStruct", :current_state => "running")) Win32::Service.should_receive(:stop).with(@new_resource.service_name) Win32::Service.should_receive(:start).with(@new_resource.service_name) @provider.restart_service @@ -174,17 +215,17 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end it "should just start the service if it is stopped" do - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "stopped"), - mock("StatusStruct", :current_state => "stopped"), - mock("StatusStruct", :current_state => "running")) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "stopped"), + double("StatusStruct", :current_state => "stopped"), + double("StatusStruct", :current_state => "running")) Win32::Service.should_receive(:start).with(@new_resource.service_name) @provider.restart_service @new_resource.updated_by_last_action?.should be_true end it "should do nothing if the service does not exist" do - Win32::Service.stub!(:exists?).with(@new_resource.service_name).and_return(false) + Win32::Service.stub(:exists?).with(@new_resource.service_name).and_return(false) Win32::Service.should_not_receive(:stop).with(@new_resource.service_name) Win32::Service.should_not_receive(:start).with(@new_resource.service_name) @provider.restart_service @@ -196,8 +237,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do describe Chef::Provider::Service::Windows, "enable_service" do before(:each) do - Win32::Service.stub!(:config_info).with(@new_resource.service_name).and_return( - mock("ConfigStruct", :start_type => "disabled")) + Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + double("ConfigStruct", :start_type => "disabled")) end it "should enable service" do @@ -207,15 +248,15 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end it "should do nothing if the service does not exist" do - Win32::Service.stub!(:exists?).with(@new_resource.service_name).and_return(false) + Win32::Service.stub(:exists?).with(@new_resource.service_name).and_return(false) Win32::Service.should_not_receive(:configure) @provider.enable_service @new_resource.updated_by_last_action?.should be_false end it "should do nothing if the service is enabled" do - Win32::Service.stub!(:config_info).with(@new_resource.service_name).and_return( - mock("ConfigStruct", :start_type => "auto start")) + Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + double("ConfigStruct", :start_type => "auto start")) Win32::Service.should_not_receive(:configure) @provider.enable_service @new_resource.updated_by_last_action?.should be_false @@ -225,8 +266,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do describe Chef::Provider::Service::Windows, "disable_service" do before(:each) do - Win32::Service.stub!(:config_info).with(@new_resource.service_name).and_return( - mock("ConfigStruct", :start_type => "auto start")) + Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + double("ConfigStruct", :start_type => "auto start")) end it "should disable service" do @@ -236,15 +277,15 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end it "should do nothing if the service does not exist" do - Win32::Service.stub!(:exists?).with(@new_resource.service_name).and_return(false) + Win32::Service.stub(:exists?).with(@new_resource.service_name).and_return(false) Win32::Service.should_not_receive(:configure) @provider.disable_service @new_resource.updated_by_last_action?.should be_false end it "should do nothing if the service is disabled" do - Win32::Service.stub!(:config_info).with(@new_resource.service_name).and_return( - mock("ConfigStruct", :start_type => "disabled")) + Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + double("ConfigStruct", :start_type => "disabled")) @provider.load_current_resource Win32::Service.should_not_receive(:configure) @provider.disable_service |