diff options
author | Daniel DeLeo <dan@opscode.com> | 2010-05-22 17:14:04 -0700 |
---|---|---|
committer | Daniel DeLeo <dan@opscode.com> | 2010-06-03 12:22:03 -0700 |
commit | b4baa5eaca7c3eb6de7f687c82226520bfad4d7a (patch) | |
tree | 2c9dc34a778d9ffc088f736912ecb5be9822335f | |
parent | f1d645bbaed93bf7c1d5870a2a4616634494acd2 (diff) | |
download | chef-b4baa5eaca7c3eb6de7f687c82226520bfad4d7a.tar.gz |
fix for updated method signatures
-rw-r--r-- | chef/lib/chef/provider/service/windows.rb | 4 | ||||
-rw-r--r-- | chef/spec/unit/provider/service/windows_spec.rb | 137 |
2 files changed, 47 insertions, 94 deletions
diff --git a/chef/lib/chef/provider/service/windows.rb b/chef/lib/chef/provider/service/windows.rb index 69920c08eb..8ef7ef9efb 100644 --- a/chef/lib/chef/provider/service/windows.rb +++ b/chef/lib/chef/provider/service/windows.rb @@ -20,8 +20,8 @@ require 'chef/provider/service/init' class Chef::Provider::Service::Windows < Chef::Provider::Service::Init - def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil) - super(node, new_resource, collection, definitions, cookbook_loader) + def initialize(new_resource, run_context) + super @init_command = "sc" end diff --git a/chef/spec/unit/provider/service/windows_spec.rb b/chef/spec/unit/provider/service/windows_spec.rb index f0ccac3078..48341394c6 100644 --- a/chef/spec/unit/provider/service/windows_spec.rb +++ b/chef/spec/unit/provider/service/windows_spec.rb @@ -22,120 +22,73 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do before(:each) do @init_command = "sc" @node = Chef::Node.new + @run_context = Chef::RunContext.new(@node, {}) + @new_resource = Chef::Resource::Service.new("chef") - @new_resource.stub!(:pattern).and_return("chef") - @new_resource.stub!(:status_command).and_return(false) + @new_resource.pattern("chef") @current_resource = Chef::Resource::Service.new("chef") - @provider = Chef::Provider::Service::Windows.new(@node, @new_resource) - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + @provider = Chef::Provider::Service::Windows.new(@new_resource, @run_context) IO.stub!(:popen).with("#{@init_command} query #{@new_resource.service_name}").and_return(['','','','4']) IO.stub!(:popen).with("#{@init_command} qc #{@new_resource.service_name}").and_return(['','','','','2']) end - it "should create a current resource with the name of the new resource" do - Chef::Resource::Service.should_receive(:new).and_return(@current_resource) - @provider.load_current_resource - end - it "should set the current resources service name to the new resources service name" do - @current_resource.should_receive(:service_name).with(@new_resource.service_name) @provider.load_current_resource + @provider.current_resource.service_name.should == 'chef' end it "should return the current resource" do - @provider.load_current_resource.should eql(@current_resource) + @provider.load_current_resource.should equal(@provider.current_resource) end -end + describe Chef::Provider::Service::Windows, "start_service" do + before(:each) do + @new_resource.start_command "sc start chef" + end -describe Chef::Provider::Service::Windows, "start_service" do - before(:each) do - @new_resource = Chef::Resource::Service.new("chef") - @new_resource.start_command "sc start chef" - - @provider = Chef::Provider::Service::Windows.new(@node, @new_resource) - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + it "should call the start command if one is specified" do + @new_resource.stub!(:start_command).and_return("#{@new_resource.start_command}") + IO.should_receive(:popen).with("#{@new_resource.start_command}").and_return(StringIO.new("foo\nbar\nbaz\n2 START_PENDING\n")) + @provider.start_service() + end end - it "should call the start command if one is specified" do - @new_resource.stub!(:start_command).and_return("#{@new_resource.start_command}") - IO.should_receive(:popen).with("#{@new_resource.start_command}").and_return(StringIO.new("foo\nbar\nbaz\n2 START_PENDING\n")) - @provider.start_service() + describe Chef::Provider::Service::Windows, "stop_service" do + it "should call the stop command if one is specified" do + @new_resource.stub!(:stop_command).and_return("#{@new_resource.stop_command}") + IO.should_receive(:popen).with("#{@new_resource.stop_command}").and_return(StringIO.new("foo\nbar\nbaz\n1 STOPPED\n")) + @provider.stop_service().should be_true + end + + it "should use the built-in command if no stop command is specified" do + @new_resource.stub!(:stop_command).and_return(nil) + IO.stub!(:popen).with("#{@init_command} stop #{@new_resource.service_name}").and_return(IO.new(2,'w')) + IO.popen("#{@init_command} stop #{@new_resource.service_name}").stub!(:readlines).and_return(["foo\n","bar\n","baz\n","1 STOPPED\n"]) + @provider.stop_service().should be_true + end end -end -describe Chef::Provider::Service::Windows, "stop_service" do - before(:each) do - @init_command = "sc" - @new_resource = Chef::Resource::Service.new("chef") - @new_resource.stop_command "sc stop chef" - - @provider = Chef::Provider::Service::Windows.new(@node, @new_resource) - Chef::Resource::Service.stub!(:new).and_return(@current_resource) - end - - it "should call the stop command if one is specified" do - @new_resource.stub!(:stop_command).and_return("#{@new_resource.stop_command}") - IO.should_receive(:popen).with("#{@new_resource.stop_command}").and_return(StringIO.new("foo\nbar\nbaz\n1 STOPPED\n")) - @provider.stop_service().should be_true - end - - it "should use the built-in command if no stop command is specified" do - @new_resource.stub!(:stop_command).and_return(nil) - IO.stub!(:popen).with("#{@init_command} stop #{@new_resource.service_name}").and_return(IO.new(2,'w')) - IO.popen("#{@init_command} stop #{@new_resource.service_name}").stub!(:readlines).and_return(["foo\n","bar\n","baz\n","1 STOPPED\n"]) - @provider.stop_service().should be_true + describe Chef::Provider::Service::Windows, "restart_service" do + it "should just call stop, then start when the resource doesn't support restart and no restart_command is specified" do + IO.should_receive(:popen).with("sc stop chef").and_return(StringIO.new("foo\nbar\nbaz\n1 STOPPED\n")) + IO.should_receive(:popen).with("sc start chef").and_return(StringIO.new("foo\nbar\nbaz\n2 START_PENDING\n")) + @provider.restart_service() + end end -end - -describe Chef::Provider::Service::Windows, "restart_service" do - before(:each) do - @init_command = "sc" - @new_resource = Chef::Resource::Service.new("chef") - @provider = Chef::Provider::Service::Windows.new(@node, @new_resource) - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + describe Chef::Provider::Service::Windows, "enable_service" do + it "should enable service and set the startup type" do + @new_resource.startup_type :automatic + IO.should_receive(:popen).with("sc config chef start= auto").and_return(StringIO.new("SUCCESS")) + @provider.enable_service().should be_true + end end - it "should just call stop, then start when the resource doesn't support restart and no restart_command is specified" do - IO.should_receive(:popen).with("#{@init_command} stop #{@new_resource.service_name}").and_return(StringIO.new("foo\nbar\nbaz\n1 STOPPED\n")) - IO.should_receive(:popen).with("#{@init_command} start #{@new_resource.service_name}").and_return(StringIO.new("foo\nbar\nbaz\n2 START_PENDING\n")) - @provider.restart_service() + describe Chef::Provider::Service::Windows, "disable_service" do + it "should disable service" do + IO.should_receive(:popen).with("sc config chef start= disabled").and_return(StringIO.new("SUCCESS")) + @provider.disable_service().should be_true + end end end - -describe Chef::Provider::Service::Windows, "enable_service" do - before(:each) do - @init_command = "sc" - @node = Chef::Node.new - @new_resource = Chef::Resource::Service.new("chef") - @new_resource.running false - @new_resource.enabled false - - @provider = Chef::Provider::Service::Windows.new(@node, @new_resource) - Chef::Resource::Service.stub!(:new).and_return(@current_resource) - end - - it "should enable service and set the startup type" do - @new_resource.startup_type :automatic - IO.should_receive(:popen).with("sc config chef start= auto").and_return(StringIO.new("SUCCESS")) - @provider.enable_service().should be_true - end -end - -describe Chef::Provider::Service::Windows, "disable_service" do - before(:each) do - @node = Chef::Node.new - @new_resource = Chef::Resource::Service.new("chef") - - @provider = Chef::Provider::Service::Windows.new(@node, @new_resource) - Chef::Resource::Service.stub!(:new).and_return(@current_resource) - end - - it "should disable service" do - IO.should_receive(:popen).with("sc config chef start= disabled").and_return(StringIO.new("SUCCESS")) - @provider.disable_service().should be_true - end -end - |